Hard to Believe, but True!
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3537   Accepted: 2024

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.
    [C. Strachey - private communication.]"

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
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

Source

分析:

思路比较简单

自己的做法:

 #include<string>
#include<cstring>
#include<iostream>
using namespace std;
int main(){//
string s;
int a[],b[],c[];
while(cin>>s){
if(s=="0+0=0"){ //注意
cout<<"True"<<endl;
break;
}
int i=;
int j=;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
while(s[i]!='+'){
a[j++]=s[i++]-'';
}
j=;
i++;
while(s[i]!='='){
b[j++]=s[i++]-'';
}
j=;
i++;
while(s[i]){
c[j++]=s[i++]-'';
//cout<<c[j-1]<<endl;
}
for(i=;i<=;i++){
a[i+]+=(a[i]+b[i])/;
a[i]=(a[i]+b[i])%;
}
for(i=;i<;i++){
if(a[i]!=c[i])
break;
}
if(i==)
cout<<"True"<<endl;
else
cout<<"False"<<endl;
}
return ;
}

网上的代码:

学习点:

1.string.find(char a):返回字符a在字符串中的位置(从0开始)

2.string.substr(a,b):返回字符串从a开始的b个字符的字符子串

 #include <iostream>
#include <string>
using namespace std;
int trans(string s) {
int a=;
for (int i=s.length()-;i>=;i--)
a=a*+s[i]-'';
return a;
}
int main() {
string s,s1,s2,s3;
while (cin >> s) {
if (s=="0+0=0") {
cout << "True" << endl;
break;
}
bool flag=true;
int p1=s.find("+");
int p2=s.find("=");
s1=s.substr(,p1);
s2=s.substr(p1+,p2-p1-);
s3=s.substr(p2+,s.length()--p2);
if (trans(s1)+trans(s2)!=trans(s3)) flag=false;
if (flag) cout << "True" << endl;
else cout << "False" << endl;
} return ;
}

poj 2572 Hard to Believe, but True!的更多相关文章

  1. POJ 2572

    #include<stdio.h> #include<iostream> #include<string> using namespace std; int mai ...

  2. 【POJ 2572 Advertisement】

    Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 947Accepted: 345Special Judge Description ...

  3. poj 1417 True Liars(并查集+背包dp)

    题目链接:http://poj.org/problem?id=1417 题意:就是给出n个问题有p1个好人,p2个坏人,问x,y是否是同类人,坏人只会说谎话,好人只会说实话. 最后问能否得出全部的好人 ...

  4. POJ 1417 - True Liars - [带权并查集+DP]

    题目链接:http://poj.org/problem?id=1417 Time Limit: 1000MS Memory Limit: 10000K Description After having ...

  5. True Liars POJ - 1417

    True Liars After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was f ...

  6. POJ 1417 True Liars(种类并查集+dp背包问题)

    题目大意: 一共有p1+p2个人,分成两组,一组p1,一组p2.给出N个条件,格式如下: x y yes表示x和y分到同一组,即同是好人或者同是坏人. x y no表示x和y分到不同组,一个为好人,一 ...

  7. POJ 1417 True Liars

    题意:有两种人,一种人只会说真话,另一种人只会说假话.只会说真话的人有p1个,另一种人有p2个.给出m个指令,每个指令为a b yes/no,意思是,如果为yes,a说b是只说真话的人,如果为no,a ...

  8. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  9. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

随机推荐

  1. Android-下载网上图片

    下载操作相关代码: package liudeli.async; import android.app.Activity; import android.app.ProgressDialog; imp ...

  2. C#+MVC+EF+LayUI框架的应用(附带源码和教程)

    内容: 1.该框架主要用到的技术有MVC,EF,Layer,以及Razor语法和数据库有关的操作. 2.框架二次开发(增加,删除,修改,建库,以及维护查询等) 3.框架公用库更新要求与规范 4.本框架 ...

  3. .net core i上 K8S(五).netcore程序的hostip模式

    上一章讲了pod的管理,今天再分享一个pod的访问方式 1.Pod的HostIP模式 Pod的HostIP模式,可以通过宿主机访问pod内的服务,创建yaml文件如下 apiVersion: v1 k ...

  4. 使用PHPstudy在Windows服务器下部署PHP系统

    PHP网站一般运行在Apache服务器上,IIS服务器上也可以运行,但是不推荐,windows服务器上没有集成Apache跟PHP的运行环境,但是借助第三方的软件就能很好的搞定,一般这样的软件有很多, ...

  5. Sql2012 AlwaysOn

    准备: 两台宿主机,两台虚拟机,一根交叉线 系统都是windows server 2012 步骤 1.两台虚拟机均为双网卡 2.配置故障转移群集 3.执行AlwaysOn配置(增加Listen此步骤上 ...

  6. 【题解】 [NOI1999]生日蛋糕

    题面 传送门 Solution 搜索每一层的半径和高度,然后加入一些剪枝就好了. #include<stdio.h> #include<stdlib.h> #include&l ...

  7. Easyui里面动态设置输入框的可见性

    JQuery EasyUI 动态隐藏   一.隐藏datagrid某一列 $('#dg').datagrid('hideColumn', 'field'); 二.隐藏html的lable.input标 ...

  8. nginx高性能WEB服务器系列之一简介及安装

    nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...

  9. 2016级算法第五次上机-E.AlvinZH的学霸养成记IV

    1039 AlvinZH的学霸养成记IV 思路 难题,最大二分图匹配. 难点在于如何转化问题,n对n,一个只能攻击一个,判断是否存在一种攻击方案我方不死团灭对方.可以想到把所有随从看作点,对于可攻击的 ...

  10. 2016级算法第二次上机-G.ModricWang's Real QuickSort

    873 思路 这是一道非常基础的题,目的是帮助大家回顾快排相关的知识.大家完成此题之后应该就对快排有比较深刻的印象了. 对于整个快排的流程,题目描述中已经给了清晰完整的伪代码.需要自己加工的部分就是, ...