[求助]Hard to Believe, but True!
http://www.informatik.uni-ulm.de/acm/Locals/2001/html/hard.html上面是题目
下面是我的解答可是输出的总是False
请帮忙看看错在哪?
#include <stdio.h>
#include <string.h>
main()
{
char a[7],b[7],c[7];
int n1[7],n2[7],n3[7],i,j,m,t,x;
while (scanf("%s+%s=%s",a,b,c))
{
for (i=0;i<strlen(a);i++)
n1[i]=a[i]-'0';
for (j=0;j<strlen(b);j++)
n2[j]=a[j]-'0';
t=0;
for (m=0;m<strlen(c);m++)
{
x=n1[m]+n2[m]+t;
if (x%10!=(c[m]-'0'))
{
printf("False\n");break;
}
else if (m==strlen(c)-1) {printf("True\n");break;}
if (x>9) t=1;
else t=0;
}
}
return 0;
}
#include <string.h>
main()
{
char a[7],b[7],c[7];
int n1[7],n2[7],n3[7],i,j,m,t,x;
while (scanf("%s+%s=%s",a,b,c))
{
for (i=0;i<strlen(a);i++)
n1[i]=a[i]-'0';
for (j=0;j<strlen(b);j++)
n2[j]=a[j]-'0';
t=0;
for (m=0;m<strlen(c);m++)
{
x=n1[m]+n2[m]+t;
if (x%10!=(c[m]-'0'))
{
printf("False\n");break;
}
else if (m==strlen(c)-1) {printf("True\n");break;}
if (x>9) t=1;
else t=0;
}
}
return 0;
}