Posted on 2008-05-13 21:56
superman 阅读(366)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1292 C++ 00:00.02 844K */
2 #include <iostream>
3
4 using namespace std;
5
6 int main()
7 {
8 int N; cin >> N;
9
10 while(N--)
11 {
12 char a[200], alen = 0; memset(a, 0, sizeof(a));
13 char b[200], blen = 0; memset(b, 0, sizeof(b));
14 char c[200], clen = 0; memset(c, 0, sizeof(c));
15
16 while(scanf("%s", b) && strcmp(b, "0") != 0)
17 {
18 memset(c, 0, sizeof(c));
19
20 blen = strlen(b);
21
22 for(int i = 0; i < blen; i++)
23 b[i] -= '0';
24 for(int i = 0; i < blen / 2; i++)
25 swap(b[i], b[blen - i - 1]);
26
27 clen = max(alen, blen);
28
29 for(int i = 0; i < clen; i++)
30 c[i] = a[i] + b[i];
31 for(int i = 0; i < clen; i++)
32 c[i + 1] += c[i] / 10, c[i] %= 10;
33
34 if(c[clen])
35 clen++;
36
37 alen = clen;
38 memcpy(a, c, sizeof(c));
39 }
40
41 for(int i = clen - 1; i >= 0; i--)
42 cout << int(c[i]);
43 cout << endl;
44
45 if(N)
46 cout << endl;
47 }
48
49 return 0;
50 }
51