Turing equation
Turing equation
时间限制: 1 Sec 内存限制: 128 MB
题目描述
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.
输入
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.
输出
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.
样例输入
73+42=16
5+8=13
0001000+000200=00030
0+0=0
样例输出
TRUE
FALSE
TRUE
题意概括
输入一个等式a+b=c,判断等式是否成立(a,b,c输入时是倒着输入的,可能存在前导零)
解题思路
输入等式之后,先将a,b,c三个整数求出来,然后判断。
代码
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <queue>
using namespace std;
int main ()
{
char str[1000];
int a,b,c,i,j,k;
while (scanf("%s",str)!=EOF)
{
if (strcmp(str,"0+0=0")==0)
break;
a = b = c = 0;
int len = strlen(str);
for (i = len-1; i >= 0; i --)
{
if (str[i]>='0' && str[i]<='9')
while (str[i]>='0' && str[i]<='9')
{
a = a*10+str[i]-'0';
i --;
}
if (str[i] == '=')
break;
}
for (j = i; j >= 0; j --)
{
if (str[j]>='0' && str[j]<='9')
while (str[j]>='0' && str[j]<='9')
{
b = b*10+str[j]-'0';
j --;
}
if (str[j] == '+')
break;
}
for (k = j; k >= 0; k --)
{
if (str[k]>='0' && str[k]<='9')
while (str[k]>='0' && str[k]<='9')
{
c = c*10+str[k]-'0';
k --;
}
}
//printf("%d %d %d\n",a,b,c);
if (c+b == a)
printf("TRUE\n");
else
printf("FALSE\n");
}
return 0;
}
Turing equation的更多相关文章
- 第七届河南省赛F.Turing equation(模拟)
10399: F.Turing equation Time Limit: 1 Sec Memory Limit: 128 MB Submit: 151 Solved: 84 [Submit][St ...
- zzuoj--10399--Turing equation(模拟)
Turing equation Time Limit: 1 Sec Memory Limit: 128 MB Submit: 152 Solved: 85 [Submit][Status][Web ...
- poj 2572 Hard to Believe, but True!
Hard to Believe, but True! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3537 Accep ...
- 每天一套题打卡|河南省第七届ACM/ICPC
A 海岛争霸 题目:Q次询问,他想知道从岛屿A 到岛屿B 有没有行驶航线,若有的话,所经过的航线,危险程度最小可能是多少. 多源点最短路,用floyd 在松弛更新:g[i][k] < g[i][ ...
- HDU3333 Turing Tree(线段树)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=3333 Description After inventing Turing Tree, 3x ...
- CodeForces460B. Little Dima and Equation
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- HDU 5937 Equation
题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...
- coursera机器学习笔记-多元线性回归,normal equation
#对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...
随机推荐
- jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第二话):安装插件,配置JDK、Git、Ant
jenkins之所以这么强大,离不开丰富的插件库. 要确保jenkins上安装好Git plugin.GitHub plugin.AntPlugin插件,一般在启动jenkins时默认安装的插件中就包 ...
- C# 定时调用方法
private void button1_Click(object sender, EventArgs e) { System.Timers.Timer timer = new System.Time ...
- DELPHI各种颜色表达式
颜色样本 十六进制 名称与注释 #ffb3a7 粉红:即浅红色.别称:妃色 杨妃色 湘妃色 妃红色. #ed5736 妃色:妃红色.古同“绯”,粉红色.杨妃色.湘妃色.粉红皆同义. #f0 ...
- (转) gffcompare和gffread | gtf | gff3 格式文件的分析 | gtf处理 | gtfparse
工具推荐:https://github.com/openvax/gtfparse 真不敢相信,Linux自带的命令会这么强大,从gtf中提取出需要的transcript,看起来复杂,其实一个grep就 ...
- 使用jquery.mobile和WebSQL实现记事本功能
1.记事本列表页 1.1.页面结构与样式: <div data-role="page" id="home"> <div data-role=& ...
- 树上第k大联通块
题意:求树上第k大联通块 n,k<=1e5 考虑转化为k短路的形式. 也就是要建出一张图是的这条图上每一条S到T的路径都能代表一个联通块. 点分治建图 递归下去,假定每个子树的所有联通块中都可以 ...
- linux中的软、硬链接
linux中的软.硬链接 硬链接 硬链接(hard link),如果文件B是文件A的硬链接,则A的inode节点号与B的inode节点号相同,即一个inode节点对应两个不同的文件名,两个文件名指向同 ...
- function_exists
在已经定义的函数列表(包括系统自带的函数和用户自定义的函数)中查找 function_name. 如果 function_name 存在且的确是一个函数就返回 TRUE ,反之则返回 FALSE .
- spring boot(十八)集成FastDFS文件上传下载
上篇文章介绍了如何使用Spring Boot上传文件,这篇文章我们介绍如何使用Spring Boot将文件上传到分布式文件系统FastDFS中. 这个项目会在上一个项目的基础上进行构建. 1.pom包 ...
- zsh切换bash bash切换zsh
切换bash(需要sudo) chsh -s /bin/bash 切换zsh(不需要sudo) chsh -s /bin/zsh 注意:如果输入命令和密码后提示:no change made. 请加上 ...