forked from improper4/uva
/
UVa10013_Superlongsums.java
45 lines (37 loc) · 1.13 KB
/
UVa10013_Superlongsums.java
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
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 954 (10013 - Super long sums) */
/* SUBMISSION: 11376333 */
/* SUBMISSION TIME: 2013-03-03 21:22:44 */
/* LANGUAGE: 2 */
import java.io.*;
import java.util.*;
public class UVa10013_Superlongsums {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(in.readLine());
boolean first = true;
while (N-- > 0) {
in.readLine();
int M = Integer.parseInt(in.readLine());
int[] n1 = new int[M];
int[] n2 = new int[M];
for (int i = 0; i < M; ++i) {
StringTokenizer stk = new StringTokenizer(in.readLine());
n1[i] = stk.nextToken().charAt(0) - '0';
n2[i] = stk.nextToken().charAt(0) - '0';
}
if (first) first = false; else System.out.println();
char[] ans = new char[M];
int carry = 0;
for (int i = M - 1; i >= 0; --i) {
int sum = n1[i] + n2[i] + carry;
ans[i] = (char)(sum % 10 + '0');
carry = sum / 10;
}
System.out.println(ans);
}
in.close();
System.exit(0);
}
}