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 ...
随机推荐
- python 爬虫登录保存会话去获取只有登录能获取的数据
#!/usr/bin/env python # -*- coding: utf-8 -*- # import ConfigParser import datetime import sys impor ...
- 7z文件格式及其源码的分析(三)
上一篇在这里. 这是7z文件格式分析的第三篇, 相信有了前两篇的准备,你已经了解了7z源码的大致结构, 以及如何简单调试7z的源码了. 很多同学是不是迫不及待想要拔去7z的神秘外衣,看看究竟了. 好 ...
- arcgis android 10.2.5开发环境配置
android里要添加arcgis android 的支持,其实本质是添加了jar包,so库,清单文件里申请了权限而已. 插件是为了方便创建arcgis android工程,然后并没有什么卵用. ar ...
- Windows store app[Part 3]:认识WinRT的异步机制
WinRT异步机制的诞生背景 当编写一个触控应用程序时,执行一个耗时函数,并通知UI更新,我们希望所有的交互过程都可以做出快速的反应.流畅的操作感变的十分重要. 在连接外部程序接口获取数据,操作本地数 ...
- 201621123012 《Java程序设计》第11周学习总结
作业11-多线程 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序BounceThread ...
- [CTSC2010]星际旅行
https://www.luogu.org/problemnew/show/P4189 题解 模拟费用流. 首先有一个非常好的条件,每个点的限制次数都大于等于这个点的度数. 然后我们可以从\(0\)开 ...
- centos6.3 配置 smb 服务
1.安装 samba 以及相关依赖包:yum install samba samba-client samba-swat 2.添加 smb 服务用户:smbpasswd -a user_name(之后 ...
- 十,PHP下载文件
1,文件类型 (1)文本文件,如xx.txt. (2)二进制文件,如图片.视频.音频. 2,文件下载流程如下图所示,首先浏览器向服务器发送下载请求,服务器将下载资源读入内存,再通过http将资源返回到 ...
- mysql主从同步错误,提示The server quit without updating PID file
在安装完lnmp后,启动mysqld失败,提示 [root@centos-6 ~]# service mysqld start Starting MySQL [确定][root@centos-6 ~] ...
- [ActionScripte 3.0] swf和网页通信
很多时候,我们需要将swf放到网页加载,并且将相应的资源都放到网页上,在网页中加载swf通常是通过"*.swf?p=..&p2=..."这样的方式来调用这个swf和传参数的 ...