A + B
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20432 Accepted Submission(s): 12241
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
直接模仿运算
AC代码如下:
#include<stdio.h> #include<string.h> int main() { char a[50]; while(gets(a)) { int f=0,j=0,A=0,B=0,i; for(i=0;i<strlen(a);i++) { if(a[i]==' '&&f==0) { if(a[j]=='o') A=A*10+1; if(a[j]=='t'&&a[j+1]=='w') A=A*10+2; if(a[j]=='t'&&a[j+1]=='h') A=A*10+3; if(a[j]=='t'&&a[j+1]=='e') A=A*10+10; if(a[j]=='f'&&a[j+1]=='o') A=A*10+4; if(a[j]=='f'&&a[j+1]=='i') A=A*10+5; if(a[j]=='s'&&a[j+1]=='i') A=A*10+6; if(a[j]=='s'&&a[j+1]=='e') A=A*10+7; if(a[j]=='e') A=A*10+8; if(a[j]=='n') A=A*10+9; if(a[j]=='z') A=A*10+0; j=i+1; } if(a[i]=='+') {f=1;i++;} if(a[i]==' '&&f==1) { if(a[j]=='o') B=B*10+1; if(a[j]=='t'&&a[j+1]=='w') B=B*10+2; if(a[j]=='t'&&a[j+1]=='h') B=B*10+3; if(a[j]=='t'&&a[j+1]=='e') B=B*10+10; if(a[j]=='f'&&a[j+1]=='o') B=B*10+4; if(a[j]=='f'&&a[j+1]=='i') B=B*10+5; if(a[j]=='s'&&a[j+1]=='i') B=B*10+6; if(a[j]=='s'&&a[j+1]=='e') B=B*10+7; if(a[j]=='e') B=B*10+8; if(a[j]=='n') B=B*10+9; if(a[j]=='z') B=B*10+0; j=i+1; } } if(A==0&&B==0) break; printf("%d\n",A+B); } return 0; }