forked from ksaveljev/UVa-online-judge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10013.cpp
48 lines (38 loc) · 765 Bytes
/
10013.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;
int main (void) {
char* result = new char[1000002];
int n, m, pos, carry, counter = 0;
char a, b;
cin >> n;
while (n--) {
counter++;
cin >> m;
pos = 0;
result[pos] = (char) 0;
for (int i = 0; i < m; i++) {
cin >> a >> b;
++pos;
result[pos] = a - '0' + b - '0';
}
carry = 0;
char temp;
for (int i = pos; i >= 0; i--) {
temp = result[i];
result[i] = (carry + temp) % 10;
carry = (carry + temp) / 10;
}
if (counter > 1) cout << endl;
for (int i = 0; i <= pos; i++) {
if (i == 0) {
if((int)result[i] > 0)
cout << (char) (result[i] + '0');
} else {
cout << (char) (result[i] + '0');
}
}
cout << endl;
}
delete result;
return 0;
}