Hard to Believe, but True!

来源:互联网 发布:windows 扩展屏幕 编辑:程序博客网 时间:2024/05/16 11:47

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=165+8=1310+20=300001000+000200=000301234+5=12391+0=07000+8000=510+0=0

Sample Output

 

TrueFalseTrueTrueFalseFalseTrueTrue/*省略了一大段的题目,其实就是说这个等式是倒着读的,如果等式正确就输出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;}
原创粉丝点击