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;
                }
    
            }
        }
     
     
     
     
     
  • 相关阅读:
    web性能优化
    比 git log 更强大的 git reflog
    父组件调用子组件的方法
    react-loadable 进行代码分割的基本使用
    create-react-app 使用 webpack 打包压缩失败
    mysql安装问题
    php 二维数组排序
    php 文件缓存 include vs serialize vs json_encode
    ab命令压力测试
    mysql使用的坑
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5309531.html
Copyright © 2011-2022 走看看