nyoj-103-A+B Problem II
1 #include<stdio.h>
2 #include<algorithm>
3 #include<string.h>
4 int main()
5 {
6 char a[1010],b[1010],c[1010];
7 int n,i,j,k,l;
8 scanf("%d",&n);
9 getchar();
10 for(l=1;l<=n;l++)
11 {
12 fflush(stdin);
13 scanf("%s %s",a,b);
14 int len1=strlen(a),len2=strlen(b);
15 c[0]='0';c[1]='\0';
16 if(len1>len2)
17 {
18 strcat(c,a);
19 for(i=len2-1,j=len1;j>=0;i--,j--)
20 {
21 if(i>=0)
22 {
23 c[j-1]+=(c[j]+(b[i]-'0')-'0')/10;
24 c[j]=(c[j]+(b[i]-'0')-'0')%10+'0';
25 }
26 else
27 {
28 c[j-1]+=(c[j]-'0')/10;
29 c[j]=(c[j]-'0')%10+'0';
30 }
31
32
33 }
34 }
35 else
36 {
37 strcat(c,b);
38 for(i=len1-1,j=len2;j>=0;i--,j--)
39 {
40 if(i>=0)
41 {
42 c[j-1]+=(c[j]+(a[i]-'0')-'0')/10;
43 c[j]=(c[j]+(a[i]-'0')-'0')%10+'0';
44 }
45 else
46 {
47 c[j-1]+=(c[j]-'0')/10;
48 c[j]=(c[j]-'0')%10+'0';
49 }
50 }
51 }
52 printf("Case %d:\n%s + %s = ",l,a,b);
53 if(c[0]=='0')
54 puts(c+1);
55 else
56 puts(c);
57 }
58 return 0;
59 }