A + B
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10194 Accepted Submission(s): 5832
Problem Description
读入两个小于100的正整数A和B,计算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
Recommend
JGShining
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 5 using namespace std; 6 7 char a[10][10]={"zero","one","two","three","four","five","six", 8 "seven","eight","nine"}; 9 10 int main() 11 { 12 int end1=0,end2=0; 13 while(true) 14 { 15 end1=0;end2=0; 16 int A=0,B=0; 17 char nu[10]; 18 int i; 19 while(scanf("%s",nu)) 20 { 21 if(strcmp(nu,"+")==0) break; 22 for(i=0;i<10;i++) 23 { 24 if(strcmp(nu,a[i])==0) 25 break; 26 } 27 A=A*10+i; 28 } 29 30 while(scanf("%s",nu)) 31 { 32 if(strcmp(nu,"=")==0) break; 33 for(i=0;i<10;i++) 34 { 35 if(strcmp(nu,a[i])==0) 36 break; 37 } 38 B=B*10+i; 39 } 40 //cout<<A<<"..."<<B<<endl; 41 if(A==0) end1=1; 42 if(B==0) end2=1; 43 if(end1==1&&end2==1) 44 break; 45 else 46 cout<<A+B<<endl; 47 } 48 49 return 0; 50 }