NYOJ 594 还是A+B
时间:2014-04-29 13:17:21
收藏:0
阅读:210
还是A+B
时间限制:1000 ms | 内存限制:65535 KB
难度:1
- 描述
-
输入两个小于100的正整数A和B,输出A+B;A,B均为每位数字对应的英文字母,结果为十进制数。
- 输入
- A,B。
- 输出
- A+B;
- 样例输入
-
one + two = one + two zero =
- 样例输出
-
3 21
-
AC码:
-
#include<stdio.h> #include<string.h> int main() { int i,j,k,sum,a; char str[30],ch[15],pt[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; while(gets(str)) // gets()函数输入的字符串允许带空格 { sum=0; for(i=0;str[i]!=‘=‘;i++) { if(str[i]==‘ ‘) continue; if(str[i]>=‘a‘&&str[i]<=‘z‘) { j=0; a=0; while((str[i]>=‘a‘&&str[i]<=‘z‘)) { ch[j]=str[i]; i++; j++; if(str[i]==‘ ‘) { ch[j]=‘\0‘; // 不要忘记在字符串末尾置‘\0‘; for(k=0;k<10;k++) { if(strcmp(ch,pt[k])==0)// 字符串比较函数 { a=a*10+k; } } j=0; i++; } } sum+=a; } if(str[i]==‘=‘) break; } printf("%d\n",sum); } return 0; }
评论(0)