zoukankan      html  css  js  c++  java
  • zoj 1969 Hard to Believe, but True!

    ZOJ Problem Set - 1969
    Hard to Believe, but True!

    Time Limit: 1 Second      Memory Limit: 32768 KB

    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: University of Ulm Local Contest 2001
    Submit    Status
    Source

    Problem Id:
    1057  User Id:wupanlei 
    Memory:848K  Time:135MS
    Language:G
    ++  Result:Accepted

    Source 

    #include 
    <iostream>
    #include 
    <cstdio>
    #define MAX 1002
    using namespace std;
    char str[MAX];
    char ch1[10],ch2[10],ch3[10];
    int main()
    {
        
    while(cin>>str)
        {

            
    if(strcmp(str,"0+0=0")==0)
            {
                printf(
    "True\n");
                
    break;
            }
            
    int i,len,starti;
            len
    =strlen(str);
            starti
    =i;
            
    int a,b,c;
            
    for(i=0;i<=len;i++)
            {
                
    if(str[i]=='+')
                {
                    a
    =i;
                }
                
    if(str[i]=='=')
                    b
    =i;
            }
            
    int k=0;
            
    for(i=a-1;i>=0;i--)
                ch1[k
    ++]=str[i];
            ch1[k]
    ='\0';
            k
    =0;
            
    for(i=b-1;i>a;i--)
                ch2[k
    ++]=str[i];
            ch2[k]
    ='\0';
            k
    =0;
            
    for(i=len-1;i>b;i--)
                ch3[k
    ++]=str[i];
            ch3[k]
    ='\0';
            
    int x=atoi(ch1),y=atoi(ch2),z=atoi(ch3);
            
    if(z==(x+y))
                printf(
    "True\n");
            
    else
                printf(
    "False\n");

        }
        
    return 0;
    }

  • 相关阅读:
    创意工坊pkg食用
    wordpress添加备案号出现乱码
    「Azure」数据分析师有理由爱Azure之四-Azure SQL的实操
    「Azure」数据分析师有理由爱Azure之三-对照Sqlserver学Azure
    「Azure」数据分析师有理由爱Azure之二-立即申请帐号开始学习之旅
    「Azure」数据分析师有理由爱Azure之一-Azure能带给我们什么?
    「Sqlserver」数据分析师有理由爱Sqlserver之十-Sqlserver自动化篇
    「Sqlserver」数据分析师有理由爱Sqlserver之九-无利益关系推荐Sqlserver书单
    「Sqlserver」数据分析师有理由爱Sqlserver之八-最刚需的数据导入导出功能-导出篇
    「Sqlserver」数据分析师有理由爱Sqlserver之七-最刚需的数据导入导出功能-导入篇
  • 原文地址:https://www.cnblogs.com/forever4444/p/1453734.html
Copyright © 2011-2022 走看看