Posted on 2008-05-07 11:05
superman 阅读(426)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1205 C++ 00:00.00 836K */
2 #include <iostream>
3
4 using namespace std;
5
6 int main()
7 {
8 while(true)
9 {
10 char a[200] = { 0 };
11 char b[200] = { 0 };
12
13 if(cin >> a >> b == false)
14 break;
15
16 int alen = strlen(a);
17 int blen = strlen(b);
18
19 for(int i = 0; i < alen / 2; i++)
20 swap(a[i], a[alen - i - 1]);
21 for(int i = 0; i < blen / 2; i++)
22 swap(b[i], b[blen - i - 1]);
23
24 for(int i = 0; i < alen; i++)
25 a[i] -= (isdigit(a[i]) ? '0' : 'a' - 10);
26 for(int i = 0; i < blen; i++)
27 b[i] -= (isdigit(b[i]) ? '0' : 'a' - 10);
28
29 char c[200] = { 0 };
30
31 int maxlen = max(alen, blen);
32 for(int i = 0; i < maxlen; i++)
33 c[i] = a[i] + b[i];
34 for(int i = 0; i < maxlen; i++)
35 c[i + 1] += c[i] / 20, c[i] %= 20;
36
37 if(c[maxlen])
38 maxlen++;
39
40 char m[] = "0123456789abcdefghij";
41 for(int i = maxlen - 1; i >= 0; i--)
42 cout << m[c[i]];
43 cout << endl;
44 }
45
46 return 0;
47 }
48