南洋理工103

 1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4
5 int main()
6 {
7 int i, T, length_a, length_b, j, k;
8 char a[1000], b[1000],c[1000];
9 scanf("%d", &T);
10 for (i=0; i<T; i++)
11 {
12 scanf("%s%s",a,b);
13 length_a = strlen(a);
14 length_b = strlen(b);
15 printf("Case %d:\n",i+1);
16 printf("%s + %s = ",a, b);
17 if (length_b < length_a)
18 {
19 strcpy(c,a);
20 strcpy(a,b);
21 strcpy(b,c);
22 k = length_b;
23 length_b = length_a;
24 length_a = k;
25 }
26 for (j=0; j<length_a; j++)
27 a[j] -= '0';
28 for (j=0; j<length_b; j++)
29 b[j] -= '0';
30 for(j=length_a-1, k=length_b-1; j>=0; k--,j--)
31 {
32 b[k] = a[j] + b[k];
33 }
34 for(j=length_b-1; j>0; j--)
35 {
36 if (b[j] > 9)
37 {
38 b[j] = b[j] - 10;
39 b[j-1] = b[j-1] + 1;
40 }
41 }
42 for (k=0; k<length_b; k++)
43 printf("%d", b[k]);
44 printf("\n");
45 }
46 return 0;
47 }
posted @ 2011-12-18 23:25  zhongya  阅读(116)  评论(0编辑  收藏  举报