C++语言: Codee#25719
01 /*
02 +++++++++++++++++++++++++++++++++++++++
03 author: chm
04 +++++++++++++++++++++++++++++++++++++++
05 */
06
07 #include <map>
08 #include <set>
09 #include <list>
10 #include <queue>
11 #include <cmath>
12 #include <stack>
13 #include <bitset>
14 #include <cstdio>
15 #include <cctype>
16 #include <vector>
17 #include <cstdlib>
18 #include <cstring>
19 #include <fstream>
20 #include <sstream>
21 #include <iomanip>
22 #include <iostream>
23 #include <algorithm>
24
25 using namespace std;
26
27 FILE* fin = stdin;
28 FILE* fout = stdout;
29 const int max_size = 10086;
30
31 char sum[max_size], numb[max_size];
32
33 void reversenumber(char* str)
34 {
35 int len = strlen(str);
36 int tmp;
37 str[len]='0'; // discard the '\0' in the end of string
38 for(int i = 0, j = len - 1; i < j; ++i, --j)
39 {
40 tmp = str[i];
41 str[i] = str[j];
42 str[j] = tmp;
43 }
44 }
45
46 int main()
47 {
48 #ifndef ONLINE_JUDGE
49 freopen("c:\\in.txt", "r", stdin);
50 fout = fopen("c:\\garage\\out.txt", "w");
51 #endif
52 memset(sum, '0', sizeof(sum));
53 memset(numb, '0', sizeof(numb));
54
55 scanf("%s\n", sum);
56 reversenumber(sum);
57 while(scanf("%s\n", numb) && numb[0] != '0')
58 {
59 reversenumber(numb);
60 int cry = 0;
61 int tmp;
62 for(int i = 0; i < 110; ++i)
63 {
64 tmp = sum[i] - '0' + numb[i] - '0' + cry;
65 sum[i] = tmp % 10 + '0';
66 cry = tmp / 10;
67 }
68 memset(numb, '0', sizeof(numb));
69 }
70 int idx = 110;
71 while(sum[idx] == '0')
72 --idx;
73 while(idx >= 0)
74 fprintf(fout, "%c", sum[idx--]);
75 fprintf(fout, "\n");
76
77 #ifndef ONLINE_JUDGE
78 fclose(fout);
79 system("c:\\garage\\check.exe");
80 system("notepad c:\\garage\\out.txt");
81 #endif
82 return 0;
83 }
02 +++++++++++++++++++++++++++++++++++++++
03 author: chm
04 +++++++++++++++++++++++++++++++++++++++
05 */
06
07 #include <map>
08 #include <set>
09 #include <list>
10 #include <queue>
11 #include <cmath>
12 #include <stack>
13 #include <bitset>
14 #include <cstdio>
15 #include <cctype>
16 #include <vector>
17 #include <cstdlib>
18 #include <cstring>
19 #include <fstream>
20 #include <sstream>
21 #include <iomanip>
22 #include <iostream>
23 #include <algorithm>
24
25 using namespace std;
26
27 FILE* fin = stdin;
28 FILE* fout = stdout;
29 const int max_size = 10086;
30
31 char sum[max_size], numb[max_size];
32
33 void reversenumber(char* str)
34 {
35 int len = strlen(str);
36 int tmp;
37 str[len]='0'; // discard the '\0' in the end of string
38 for(int i = 0, j = len - 1; i < j; ++i, --j)
39 {
40 tmp = str[i];
41 str[i] = str[j];
42 str[j] = tmp;
43 }
44 }
45
46 int main()
47 {
48 #ifndef ONLINE_JUDGE
49 freopen("c:\\in.txt", "r", stdin);
50 fout = fopen("c:\\garage\\out.txt", "w");
51 #endif
52 memset(sum, '0', sizeof(sum));
53 memset(numb, '0', sizeof(numb));
54
55 scanf("%s\n", sum);
56 reversenumber(sum);
57 while(scanf("%s\n", numb) && numb[0] != '0')
58 {
59 reversenumber(numb);
60 int cry = 0;
61 int tmp;
62 for(int i = 0; i < 110; ++i)
63 {
64 tmp = sum[i] - '0' + numb[i] - '0' + cry;
65 sum[i] = tmp % 10 + '0';
66 cry = tmp / 10;
67 }
68 memset(numb, '0', sizeof(numb));
69 }
70 int idx = 110;
71 while(sum[idx] == '0')
72 --idx;
73 while(idx >= 0)
74 fprintf(fout, "%c", sum[idx--]);
75 fprintf(fout, "\n");
76
77 #ifndef ONLINE_JUDGE
78 fclose(fout);
79 system("c:\\garage\\check.exe");
80 system("notepad c:\\garage\\out.txt");
81 #endif
82 return 0;
83 }