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;}
- Hard to Believe, but True!
- Hard to Believe, but True!
- FZU 1171 Hard to Believe, but True!
- poj2572 Hard to Believe, but True!
- 【FOJ 1171】 Hard to Believe, but True!
- fzu 1171 Hard to Believe, but True!
- FZU1171 Hard to Believe, but True!
- poj 2572 Hard to Believe, but True!(字符串)
- ACM篇:POJ 2572 -- Hard to Believe, But True!
- POJ 2572 Hard to Believe, but True! G++
- Hard to Believe, but True!(大数加法的模板和atoi()的应用)
- EOJ 1424/FOJ 1171/POJ 2572/ZOJ 1969/Ulm Local 2001 Hard to Believe, but True!
- How naive it's to believe node.js good for IO but bad for Computation?
- Spring is infinitely good, but hard to find clear Huan
- TO SEE IS TO BELIEVE
- 235. It is easy to open a shop but hard to keep it always open. 创业容易守业难
- roman doesn't be built in one day; but several years ` but you have to build it hard for every day
- Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in.
- Android应用程序开发教程 - 实现一个登录对话框
- 眼中的世界
- Create Cool Line Effects using Actionscript 3.0 in Flash CS4 or Flex Builder 3
- 如何实现dorado的datatable整列单选效果
- 转)DB2 未发出启动数据库管理器的命令的几个问题
- Hard to Believe, but True!
- C#清除页面缓存
- 怎样才能生活的愉快——学会与人沟通
- 中国电子商务10年嬗变路线图
- JSP 文件 下载 代码 (不使用 jsp smart upload 组件) 解决中文名 问题
- sqlserver 中文簡繁體保存時注意的問題,無法解析 equal to 動作的定序衝突,亂碼
- ASP.NET Session State Partitioning using State Server Load Balancing
- Oracle Certification Study Guides and Oracle Certification Sample Questions
- 格林斯潘