天天看点

Hard to Believe, but True!

Input Specification

The input contains several test cases. Each specifies on a single line a Turing equation. A Turing equation has the form "a+b=c", where a, b, c are numbers made up of the digits 0,...,9. Each number will consist of at most 7 digits. This includes possible leading or trailing zeros. The equation "0+0=0" will finish the input and has to be processed, too. The equations will not contain any spaces.

Output Specification

For each test case generate a line containing the word "True" or the word "False", if the equation is true or false, respectively, in Turing's interpretation, i.e. the numbers being read backwards.

Sample Input

73+42=16
5+8=13
10+20=30
0001000+000200=00030
1234+5=1239
1+0=0
7000+8000=51
0+0=0
      

Sample Output

True
False
True
True
False
False
True
True
/*省略了一大段的题目,其实就是说这个等式是倒着读的,如果等式正确就输出TRUE,相加减就比较容易,但是数前面多几个零就比较难处理,      
此时stoi()函数就派上大用场了,他可以把字符型化成10进制并且忽略字符串前面多余的0,这下问题变得简单了,只要把两个加数处理下,化成整形      
相加,再比较和是否与给出的相等,如果有更好的方法可以告诉我哦*/      
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
register int i,j,k;
char a[24];
char m[8],n[8],sum[8];
while(1)
{scanf("%s",a);
if(strcmp(a,"0+0=0")==0) {printf("True/n");break;}
i=0;
while(a[i]!='+') {i++;}
for(k=0,j=i-1;j>=0;j--,k++)
{m[k]=a[j];}
m[k]='/0';
while(a[i]!='=') {i++;}
for(k=0,j=i-1;a[j]!='+';j--,k++)
n[k]=a[j];n[k]='/0';
for(k=0,j=strlen(a)-1;j>i;j--,k++)
sum[k]=a[j];sum[k]='/0';
if(atoi(m)+atoi(n)==atoi(sum)) printf("True/n");
else printf("False/n");
}return 0;}