NYOJ 1253 Turing equation【题意是关键,模拟】

Turing equation

时间限制:1000 ms  |  内存限制:65535 KB

难度:1

描述

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
来源
第七届河南省程序设计大赛

原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=1253

题意:输入的数都是反的,判断等式是否成立。

eg1: 73 + 42 = 16  ------->37 + 24 = 61

eg3: 0001000+000200=00030 --------> 0001000 + 002000 = 03000

原来打算用sscanf()函数的,再把读到的数反读,后来发现第三组数据过不了。

那就老老实实模拟吧。

AC代码:

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    char a[30];
    //freopen("data/1253.txt","r",stdin);
    while(cin>>a)
    {
        if(!strcmp("0+0=0",a))
            break;
        int len=strlen(a);
        int b[5];
        memset(b,0,sizeof(b));
        int k=0;
        for(int i=len-1;i>=0;i--)
        {
            if(isdigit(a[i]))
                b[k]=b[k]*10+a[i]-'0';
            else
                k++;
        }
        if(b[0]==b[1]+b[2])
            cout<<"TRUE"<<endl;
        else
            cout<<"FALSE"<<endl;
    }
    return 0;
}
时间: 2024-08-30 00:52:14

NYOJ 1253 Turing equation【题意是关键,模拟】的相关文章

NYOJ 179 LK&#39;s problem (排序模拟)

链接:click here~~ 题意: 描述 LK has a question.Coule you help her? It is the beginning of the day at a bank, and a crowd  of clients is already waiting for the entrance door to  open. Once the bank opens, no more clients arrive, and  tellerCount tellers be

nyoj1253 Turing equation(第七届河南省程序设计大赛)

题目1253 题目信息 运行结果 本题排行 讨论区 Turing equation 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 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

NYOJ 52 无聊的小明 【模拟】

无聊的小明 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述       这天小明十分无聊,没有事做,但不甘于无聊的小明聪明的想到一个解决无聊的办法,因为他突然对数的正整数次幂产生了兴趣. 众所周知,2的正整数次幂最后一位数总是不断的在重复2,4,8,6,2,4,8,6--我们说2的正整数次幂最后一位的循环长度是4(实际上4的倍数都可以说是循环长度,但我们只考虑最小的循环长度).类似的,其余的数字的正整数次幂最后一位数也有类似的循环现象. 这时小明的问题就出来了:是不

每天一套题打卡|河南省第七届ACM/ICPC

A 海岛争霸 题目:Q次询问,他想知道从岛屿A 到岛屿B 有没有行驶航线,若有的话,所经过的航线,危险程度最小可能是多少. 多源点最短路,用floyd 在松弛更新:g[i][k] < g[i][j] && g[k][j] < g[i][j]时,g[i][j] = max(g[i][k],g[k][j]); #include<bits/stdc++.h> using namespace std; const int maxn = 510; int n,m; int q

luoguoj 1598 垂直柱状图 模拟

P1598 垂直柱状图 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.luogu.org/problem/show?pid=1598 Description 写一个程序从输入文件中去读取四行大写字母(全都是大写的,每行不超过72个字符),然后用柱状图输出每个字符在输入文件中出现的次数.严格地按照输出样例来安排你的输出格式. Input 四行字符,由大写字母组成,每行不超过72个字符 Output 由若干行组成,前几行由空格和星号

cdoj 25 点球大战(penalty) 模拟题

点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/25 Description 在足球比赛中,有不少赛事,例如世界杯淘汰赛和欧洲冠军联赛淘汰赛中,当比赛双方经过正规比赛和加时赛之后仍然不分胜负时,需要进行点球大战来决定谁能够获得最终的胜利.点球大战的规则非常简单,两方轮流派出球员罚点球,每方各罚5个.当5轮点球结束以后如果仍然不分胜负,则进入一轮定胜

nyoj 1278G: Prototypes analyze 与 二叉排序树(BST)模板

参考博客:https://blog.csdn.net/stpeace/article/details/9067029 参考博客:https://blog.csdn.net/baidu_35643793/article/details/70792326 先放上二叉搜索树的板子 #include <iostream> using namespace std; // BST的结点 typedef struct node { int key; struct node *lChild, *rChild;

[考试反思]1027csp-s模拟测试90:自我

其实这套题很好. 但是这次,在T1爆炸的同时,T2和T3并没有出现能弥补的表现. 在AK仍然存在的同时,我居然连一个AC都没有. 所以最后就是一无是处的一场. 考试结束前估分:100+100+30=230 结果T1和T2都没有A... T1乖乖的按照题意打大模拟,没算复杂度,开心的一匹... T2位运算判定锅了,判断两个数二进制下的某几位是否相同不能与运算完再与原数判. 看到这句红色加粗的话我自己也想笑了...怎么能做到这么蠢的啊..? 思路倒是对的,炸了50分. T3想到线段树的正解,但是感觉

第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安站

 第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安赛区总结报告 报告人:田思明 队名:ACpioneer 队长:陈志阳,队员:顾振兴,田思明 西安区域赛告下帷幕,我和陈志阳,顾振兴组成的ACpioneer队最终获得了一块宝贵的铜牌.首先要感谢陈志阳和顾振兴两位杰出队友的努力训练和出色表现,我作为一个新人跟着他们学到了很多很多,也十分珍惜和他们在一起的训练,比赛时光,其次要感谢陈志老师,不辞辛劳陪我们5队和6队前往西安参加比赛,还要感谢集训队所有曾经帮过我们的所有队员们,记得cdy