zoukankan      html  css  js  c++  java
  • hdu 1228

    Description

    读入两个小于100的正整数A和B,计算A+B. 
    需要注意的是:A和B的每一位数字由对应的英文单词给出. 
     

    Input

    测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出. 
     

    Output

    对每个测试用例输出1行,即A+B的值. 
     

    Sample Input

    one + two = three four + five six = zero seven + eight nine = zero + zero =
     

    Sample Output

    3 90 96
     
     
    考虑好空格和加数的位数就可以了
    #include<bits/stdc++.h>
    #define one 1
    #define two 2
    #define three 3
    #define four 4
    #define five 5
    #define six 6
    #define seven 7
    #define eight 8
    #define nine 9
    #define zero 0
    using namespace std;
        char a[100];
        int i=0;
        int t=0;
        int num[4];
        int con=0;
        int flag=0;
    int main()
    {
    
        while(scanf("%c",&a[i])){
            if(a[i]>='a'&&a[i]<='z')
                {
                    con++;
                    i++;
                }
                else if(a[i]=='+') {i++;flag =t;}
                else if(a[i]!='=')
                {
    
                    if(con==3)
                    {
                        if(a[i-3]=='o'&&a[i-2]=='n') num[t++]=1;
                        else if(a[i-3]=='t'&&a[i-2]=='w') num[t++]=2;
                        else if(a[i-3]=='s') num[t++]=6;
                    }
                    else if(con==4)
                    {
                        if(a[i-2]=='u') num[t++]=4;
                        else if(a[i-2]=='v') num[t++]=5;
                        else if(a[i-2]=='n') num[t++]=9;
                        else if(a[i-2]=='r') num[t++]=0;
                    }
                    else if(con==5)
                    {
                        if(a[i-1]=='e') num[t++]=3;
                        else if(a[i-1]=='n') num[t++]=7;
                        else if(a[i-1]=='t') num[t++]=8;
                     }
                    con=0;
                    i++;
                }
                else if(a[i]=='=')
                {
                    if(num[0]==num[1]&&num[0]==0) return 0;
                    if(t==2) cout<<num[0]+num[1]<<endl;
                    else if(t==3&&flag==2) cout<<num[0]*10+num[1]+num[2]<<endl;
                    else if(t==3&&flag==1) cout<<num[0]+num[1]*10+num[2]<<endl;
                    else cout<<num[0]*10+num[1]+num[2]*10+num[3]<<endl;
                    memset(a,NULL,sizeof(a));
                    i=0;
                    con=0;
                    memset(num,NULL,sizeof(num));
                    t=0;
                    flag=0;
                }
    
            }
        }
     
     
     
     
     
  • 相关阅读:
    前端 fetch 通信
    编写高质量的JavaScript代码(一)
    Redis学习笔记1-Redis的介绍和认识
    gitignore不起作用解决的方法
    【我的面经】说说简历的细节——软件开发岗位
    菜鸟的mongoDB学习---(七)MongoDB 备份(mongodump)与恢复(mongorerstore)
    HDU 4927 Series 1
    树状数组求第K小值 (spoj227 Ordering the Soldiers &amp;&amp; hdu2852 KiKi&#39;s K-Number)
    git和SVN的差别
    KVM-Introduce
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5309531.html
Copyright © 2011-2022 走看看