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; }
原文地址:http://blog.csdn.net/u012804490/article/details/24691297