Turing equation
問題 F: F.Turing equation
時間限制:?1 Sec??內存限制:?128 MB
提交:?19??解決:?1
[提交][狀態][討論版]
題目描述
The fight goes on,whether to store?numbers starting with their most significant digit ortheir least?significant digit. Sometimes?this?is alsocalled?the?"Endian War". The battleground?dates farback into the early days of computer?science. Joe Stoy,?in his (bythe way excellent)?book?"Denotational Semantics", tellsfollowing story:
"Thedecision?which way round the digits run is,?of course, mathematicallytrivial. Indeed,?one early British computer?had numbers running fromright to left (because the?spot on an oscilloscope tube?runs fromleft to right, but?in serial logic the least significant digits are dealtwith first). Turing used to mystify audiences at public lectures when, quite byaccident, he would slip into this mode even for decimal arithmetic, andwrite?things?like 73+42=16.?The next version of?the machinewas?made?more conventional simply?by crossing the x-deflectionwires:?this,?however, worried the engineers, whosewaveforms?were all backwards. That problem was in turn solved by providinga little window so that the engineers (who tended to be behind the computeranyway) could view the oscilloscope screen from the back.
?
You will play therole of the audience and judge on the truth value of Turing's equations.
輸入
he input containsseveral test cases. Each specifies on a single line a Turing equation. A Turingequation has the form "a+b=c", where a, b, c are numbers made up ofthe digits 0,...,9. Each number will consist of at most 7 digits. This includespossible leading or trailing zeros. The equation "0+0=0" will finishthe input and has to be processed, too. The equations will not contain anyspaces.
輸出
For each test casegenerate a line containing the word "TRUE" or the word"FALSE", if the equation is true or false, respectively, in Turing'sinterpretation, i.e. the numbers being read backwards.
樣例輸入
73+42=16
5+8=13
0001000+000200=00030
0+0=0
樣例輸出
TRUE
FALSE
TRUE
cpp:
#include<stdio.h> #include<string.h> int main(void) { char str[110]; while(gets(str)) { int num1=0,num2=0,num3=0; int i,j,k; int len1=strlen(str)-1; for(i=len1;i>=0;i--) { if(str[i]=='=') j=i; if(str[i]=='+') k=i; } for(i=len1;i>j;i--) { num3=num3*10+(str[i]-48); } for(i=j-1;i>k;i--) { num2=num2*10+(str[i]-48); } for(i=k-1;i>=0;i--) { num1=num1*10+(str[i]-48); } if(num1==0&&num2==0&&num3==0) break; else if(num1+num2==num3) { printf("TRUE\n"); } else { printf("FALSE\n"); } } return 0; }總結
以上是生活随笔為你收集整理的Turing equation的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python连连看小游戏_利用Pytho
- 下一篇: 华南理工大学广州学院计算机二级,华南理工