当前位置 : 主页 > 手机开发 > harmonyos >

航电ACM HDU 1228 A + B

来源:互联网 收集:自由互联 发布时间:2023-08-26
A + B Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9374Accepted Submission(s): 5364 Problem Description 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一


A + B

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9374    Accepted Submission(s): 5364


Problem 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


 


 


Source


浙大计算机研究生复试上机考试-2005年


 


 


Recommend


JGShining


 


 

#include <cstdio>
#include <string.h>
int f(char str[]){
    if(!strcmp(str,"zero"))return 0;
    if(!strcmp(str,"one"))return 1;
    if(!strcmp(str,"two"))return 2;
    if(!strcmp(str,"three"))return 3;
    if(!strcmp(str,"four"))return 4;
    if(!strcmp(str,"five"))return 5;
    if(!strcmp(str,"six"))return 6;
    if(!strcmp(str,"seven"))return 7;
    if(!strcmp(str,"eight"))return 8;
    if(!strcmp(str,"nine"))return 9;
}
int main(){
    char str[30];
    int a,b;
    while(1){
        a=b=0;
        while(1){
            scanf("%s",str);
            if(!strcmp(str,"+"))break;
            else a=a*10+f(str);
        }
        while(1){
            scanf("%s",str);
            if(!strcmp(str,"="))break;
            else b=b*10+f(str);
        }
        if(a==0&&b==0)break;
        printf("%d\n",a+b);
    }
}

 

上一篇:杭电ACM HDU 1008
下一篇:没有了
网友评论