nyoj 103-A+B problems 2

http://acm.nyist.net/JudgeOnline/problem.php?pid=103

这题是一个大数水题,最基本的大数题,本来不想贴这题,只是做一下放松一下,结果一直wa~~~最后才发现只是因为0+0 = 0时没有输出~~~

贴在这里以示警戒~~~什么时候都要注意细节,不能轻视任何一道题

 1 #include<stdio.h>
2 #include<string.h>
3 int a[1010], b[1010];
4 char s1[1010], s2[1010];
5
6 void changenum(char *s, int *a)
7 {
8 int t;
9 int start, end, i;
10 start = 0;
11 end = strlen(s) - 1;
12 for(i = 0; i < (int)strlen(s); i++)
13 {
14 a[i] = s[i] - '0';
15 }
16 while(start < end)
17 {
18 t = a[start];
19 a[start] = a[end];
20 a[end] = t;
21 start++;
22 end --;
23 }
24 }
25
26 int main()
27 {
28 int i, ncases, l, j;
29 scanf("%d", &ncases);
30 for(j = 0; j < ncases; j++)
31 {
32 memset(a, 0, sizeof(a));
33 memset(b, 0, sizeof(b));
34 scanf("%s%s", s1, s2);
35 changenum(s1, a);
36 changenum(s2, b);
37 for(i = 0; i < 1010; i++)
38 {
39 a[i] = a[i] + b[i];
40 if(a[i] > 9)
41 {
42 a[i] %= 10;
43 a[i+1]++;
44 }
45 }
46 for(i = 1009; i >= 0; i--)
47 {
48 if(a[i])
49 break;
50 }
51 printf("Case %d:\n%s + %s = " , j+1, s1, s2);
52 if(i < 0)
53 printf("0");
54 for(;i >= 0; i--)
55 printf("%d", a[i]);
56 putchar(10);
57 }
58 return 0;
59 }

 

posted @ 2011-12-18 19:36  枫萧萧  阅读(221)  评论(0编辑  收藏  举报