10399: F.Turing equation

Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 151  Solved: 84 [Submit][Status][Web Board]

Description

The fight goes on, whether to store  numbers starting with their most significant digit or their least  significant digit. Sometimes  this  is also called  the  "Endian War". The battleground  dates far back into the early days of computer  science. Joe Stoy,  in his (by the way excellent)  book  "Denotational Semantics", tells following story:
"The decision  which way round the digits run is,  of course, mathematically trivial. Indeed,  one early British computer  had numbers running from right to left (because the  spot on an oscilloscope tube  runs from left to right, but  in serial logic the least significant digits are dealt with first). Turing used to mystify audiences at public lectures when, quite by accident, he would slip into this mode even for decimal arithmetic, and write  things  like 73+42=16.  The next version of  the machine was  made  more conventional simply  by crossing the x-deflection wires:  this,  however, worried the engineers, whose waveforms  were all backwards. That problem was in turn solved by providing a little window so that the engineers (who tended to be behind the computer anyway) could view the oscilloscope screen from the back.
You will play the role of the audience and judge on the truth value of Turing's equations.

Input

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

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
0001000+000200=00030
0+0=0

Sample Output

TRUE
FALSE
TRUE

HINT

 

Source

题解:把数字反转问等式是否成立;

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
char s[35],t[10];
int ans[3];
int main(){
while(scanf("%s",s),strcmp(s,"0+0=0")){
int k=0,tp=0,temp=0;
for(int i=0;s[i];i++){
if(isdigit(s[i])){
t[k++]=s[i];
}
else{
reverse(t,t+k);
for(int j=0;j<k;j++)
temp=temp*10+t[j]-'0';
ans[tp++]=temp;
k=0;temp=0;
}
}
reverse(t,t+k);
for(int j=0;j<k;j++)
temp=temp*10+t[j]-'0';
ans[tp++]=temp;
// printf("%d %d %d\n",ans[0],ans[1],ans[2]);
if(ans[0]+ans[1]==ans[2])puts("TRUE");
else puts("FALSE");
}
return 0;
}

  

第七届河南省赛F.Turing equation(模拟)的更多相关文章

  1. 第七届河南省赛10403: D.山区修路(dp)

    10403: D.山区修路 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 69  Solved: 23 [Submit][Status][Web Bo ...

  2. 第七届河南省赛10402: C.机器人(扩展欧几里德)

    10402: C.机器人 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 53  Solved: 19 [Submit][Status][Web Boa ...

  3. 第七届河南省赛G.Code the Tree(拓扑排序+模拟)

    G.Code the Tree Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 35  Solved: 18 [Submit][Status][Web ...

  4. 第七届河南省赛B.海岛争霸(并差集)

    B.海岛争霸 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 130  Solved: 48 [Submit][Status][Web Board] D ...

  5. 第七届河南省赛A.物资调度(dfs)

    10401: A.物资调度 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 95  Solved: 54 [Submit][Status][Web Bo ...

  6. 第七届河南省赛H.Rectangles(lis)

    10396: H.Rectangles Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 229  Solved: 33 [Submit][Status] ...

  7. 第八届河南省赛F.Distribution(水题)

    10411: F.Distribution Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 11  Solved: 8 [Submit][Status] ...

  8. 算法笔记_122:蓝桥杯第七届省赛(Java语言A组)试题解答

     目录 1 煤球数目 2 生日蜡烛 3 搭积木 4 分小组 5 抽签 6 寒假作业 7 剪邮票 8 取球博弈 9 交换瓶子 10 压缩变换   前言:以下试题解答代码部分仅供参考,若有不当之处,还请路 ...

  9. 山东省第七届省赛 D题:Swiss-system tournament(归并排序)

    Description A Swiss-system tournament is a tournament which uses a non-elimination format. The first ...

随机推荐

  1. css复合属性的写法

    # 复合属性也称为 "shortcut" property (快捷属性),它作用是为了简化代码,提高页面运行的效率. # 下面的内容会介绍 2 个比较常用的复合属性 "f ...

  2. C语言 格式说明符

    整数 lL代表long %#0 和%#x 可打印出八进制和十六进制前缀 short int long long long 无符号 八进制 %ho %o %Lo %LLo 十进制 %hu %u %Lu ...

  3. http://webhelp.esri.com/arcgisexplorer/2500/zh-CN/index.html#add_raster_data.htm

    http://webhelp.esri.com/arcgisexplorer/2500/zh-CN/index.html#add_raster_data.htm

  4. 数组Magic Index

    Question A magic index in an array A[1...n-1] is defined to be an index such that A[i] = i. Given a ...

  5. UVA1351-----String Compression-----区间DP(记忆化搜索实现)

    本文出自:http://blog.csdn.net/dr5459 题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&a ...

  6. git操作标签

    操作标签 如果标签打错了,也可以删除: $ git tag -d v0.1 Deleted tag 'v0.1' (was e078af9) 因为创建的标签都只存储在本地,不会自动推送到远程.所以,打 ...

  7. 解决Node.js调用fs.renameSync报错的问题(Error: EXDEV, cross-device link not permitted)

    2014-08-23 今天开始学习Node.js,在写一个文件上传的功能时候,调用fs.renameSync方法错误 出错代码所在如下: function upload(response,reques ...

  8. Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)

    Pat1043代码 题目描写叙述: A Binary Search Tree (BST) is recursively defined as a binary tree which has the f ...

  9. SQLSERVER常用脚本整理

    数据库存储空间查询(数据库的大小及数据库中各个表的数据量和每行记录大小) IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = Object_i ...

  10. 全球最快的JS模板引擎

    废话不多说,先上测试: 亲测请访问:[在线测试地址]单次结果不一定准确,请多测几次. tppl 的编译渲染速度是著名的 jQuery 作者 John Resig 开发的 tmpl 的 43 倍!与第二 ...