/*========================================================================
题目1010:A + B
时间限制:1 秒内存限制:32 兆
题目描述:
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
输入:
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
输出:
对每个测试用例输出1行,即A+B的值.
样例输入:
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
样例输出:
3
90
96
来源:
2005年浙江大学计算机及软件工程研究生机试真题
==========================================================================*/
![]()
1 #include<stdio.h>
2 #include<string.h>
3 char a[10][30]={"zero","one","two","three","four","five","six","seven","eight","nine"};
4 int fun(char t[])
5 {
6 int i=0;
7 while(t[i]!='\0')
8 {
9 if(t[i]>='A'&&t[i]<='Z')
10 {
11 t[i]=t[i]+32;
12 }
13 i++;
14 }
15 for(i=0;i<10;i++)
16 {
17 if(strcmp(t,a[i])==0) return i;
18 }
19 }
20 int main()
21 {
22 int a,b,c;
23 char t[30];
24 freopen("1010.in","r",stdin);
25 while(scanf("%s",t)!=EOF)
26 {
27 a=0;
28 while(strcmp(t,"+")!=0)
29 {
30 c=fun(t);
31 a=a*10+c;
32 scanf("%s",t);
33 }
34
35 b=0;
36 scanf("%s",t);
37 while(strcmp(t,"=")!=0)
38 {
39 c=fun(t);
40 b=b*10+c;
41 scanf("%s",t);
42 }
43 if(a!=0&&b!=0)
44 printf("%d\n",a+b);
45 }
46 return 0;
47 }
View Code