杭电1002问题求指点。
Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input
2
1 2
112233445566778899 998877665544332211
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
http://acm.hdu.
#include<stdio.h>
#include<string.h>
#define N 1001
char a[N], b[N];
int c[N]={0}, d[N]={0};
int main()
{
int i, j, m, n, t, h, k, l1, l2;
scanf("%d", &h);
for(i = 1; i <= h; i++)
{
scanf("%s",a);
scanf("%s",b);
l1 = strlen(a);
l2 = strlen(b);
if(l1 < l2)
k = l2;
else
k = l1; t = k;
for(j = 0;j < l1; k--,j++)
c[k] = a[l1-1-j] - '0';
k = t;
for(j = 0;j < l2; k--,j++)
d[k] = b[l2-1-j] - '0';
for(j = t; j >= 0; j--)
{
c[j] += d[j];
if(c[j] >= 10)
{
c[j] -= 10;
c[j-1]++;
}
}
printf("Case %d:\n", i);
printf("%s + %s = ", a, b);
if(c[0] == 0)
for(j = 1; j <= t; j++)
printf("%d",c[j]);
else
for(j = 0; j <= t; j++)
printf("%d",c[j]);
printf("\n");
if(i != h)
printf("\n");
}
return 0;
}
为什么自己运行的对,但是提交后wrong呢。