poj 2572 Hard to Believe, but True!
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3537 | Accepted: 2024 |
Description
- "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
Output
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!的更多相关文章
- POJ 2572
#include<stdio.h> #include<iostream> #include<string> using namespace std; int mai ...
- 【POJ 2572 Advertisement】
Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 947Accepted: 345Special Judge Description ...
- poj 1417 True Liars(并查集+背包dp)
题目链接:http://poj.org/problem?id=1417 题意:就是给出n个问题有p1个好人,p2个坏人,问x,y是否是同类人,坏人只会说谎话,好人只会说实话. 最后问能否得出全部的好人 ...
- POJ 1417 - True Liars - [带权并查集+DP]
题目链接:http://poj.org/problem?id=1417 Time Limit: 1000MS Memory Limit: 10000K Description After having ...
- True Liars POJ - 1417
True Liars After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was f ...
- POJ 1417 True Liars(种类并查集+dp背包问题)
题目大意: 一共有p1+p2个人,分成两组,一组p1,一组p2.给出N个条件,格式如下: x y yes表示x和y分到同一组,即同是好人或者同是坏人. x y no表示x和y分到不同组,一个为好人,一 ...
- POJ 1417 True Liars
题意:有两种人,一种人只会说真话,另一种人只会说假话.只会说真话的人有p1个,另一种人有p2个.给出m个指令,每个指令为a b yes/no,意思是,如果为yes,a说b是只说真话的人,如果为no,a ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
随机推荐
- HTTP 常见异常状态及Delphi IDHTTP 控件处理方式
以下部分为网上查找,部分为工作中整理 200:请求成功 202:请求被接受,但处理尚未完成 302:请求到的资源在一个不同的URL处临时保存 处理方式:重定向到临时的URL(IDHTTP处理方 ...
- CentOS中安装Java环境 jdk
一. 在CentOS中只需要先移除自带的OpenJava,再安装原生的Java SDK. <1> rpm -qa | grep jdk: 也就是query all npm 包,找 ...
- 使用.net core 自带DI框架实现 延迟加载
在某些情况,我们希望能延迟一个依赖的初始化.如果使用的是autofac,我们可以通过注入Lazy来实现. 我们对 autofac GitHub上提供的一个例子进行进行简单改造,跑起来看看. 原Exam ...
- IdentityServer4与ocelot实现认证与客户端统一入口
关于IdentityServer4与ocelot博客园里已经有很多介绍我这里就不再重复了. ocelot与IdentityServer4组合认证博客园里也有很多,但大多使用ocelot内置的认证,而且 ...
- C#连接MySql数据库代码
之前学JAVA的时候,老师讲数据库的时候,讲到可以用一个类来连接数据库,叫做Dao层,今天要用C#做上位机,也有一些数据要写到数据库中去,我就想,能不能也给C#写一个这样的Dao层来连接数据库,我就去 ...
- 2018版OCP考试052最新题库及答案-35题
35.Your database is using Automatic Memory Management. Which two SGA components must be managed manu ...
- 微信小程序之WebSocket
本文版权归 OSChina jsongo0 所有,转载请标明出处,以示尊重! 原文:https://my.oschina.net/jsongo/blog/757871 为什么需要websocket?传 ...
- sqlalchemy中使用event设置条件触发短信与邮件通知
一.原因 近期在做短信与邮件通知系统.使用到了这一块.例如,当订单完成以后进行邮件短信的通知.虽然可以采用直接调用接口的方式实现,但有几个原因让我希望使用条件触发的方式 1.由于系统中支持线上线下以及 ...
- TX 下常用的查询指令
查看Jetson TX2 L4T版本 head -n 1 /etc/nv_tegra_release 查看系统版本 cat /etc/lsb-release 查看系统l内核 uname -a 查看内存 ...
- CoreText 图文混排
基本原理 https://www.cnblogs.com/purple-sweet-pottoes/p/5109413.html CoreText(一):基本用法 https://blog.csdn ...