HDOJ 1002题 代码写出来了,但总是WA,望指导
我刚刚发现还有一个代码功能,就把代码复制一遍,又在第三楼发了一遍#include <stdio.h>
#include <string.h>
int main()
{
char str1[1024],str2[1024],c[1025];
int n1 = 0;
int n2 = 0;
int i,j,k,n,t1,t2;
k = 0;
j = 0;
scanf("%d", &n);
while (++j)
{
if(j > n)
break;
scanf("%s%s", str1, str2);
t1 = n1 = strlen(str1)-1;
t2 = n2 = strlen(str2)-1;
for(i=0; i<=n1||i<=n2; i++)
{
if(i > n1)
k = str2[t2--] - '0' + k;
else if(i > n2)
k = str1[t1--] - '0' + k;
else
k = str1[t1--]+str2[t2--]-2*'0' + k;
if(k>=10)
{
c[i] = k%10 + '0';
k = 1;
}
else
{
c[i] = k + '0';
k = 0;
}
}
if(k == 1)
{
c[i] = 1 + '0';
c[i+1] = 0;
}
else
{
c[i] = 0;
}
printf("Case %d:\n", j);
printf("%s + %s = ", str1, str2);
while(i>=0)
{
printf("%c", c[i]);
i--;
}
if(j != n-1)
printf("\n\n");
}
return 0;
}
[此贴子已经被作者于2016-2-7 18:24编辑过]