题目1010:A + B------------------------此种输入方法令我打开眼界

主要就是输入一长串的字符,如何从中摘出单个的字符换成数字:

AC:

/**********************************/
令人头疼的是如何输入这些:
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
通过下面这道题,学习了好多
/**********************************/


#include<stdio.h> #include<cstring> char str[10][8]={"zero","one","two","three","four","five","six","seven","eight","nine"}; int find(char *tem) { int i=0; for (i=0;i<10;i++) if (strcmp(tem,str[i])==0) return i; return 0; } int main() { char temp[10]; while(scanf("%s",&temp)!=EOF) { int t1=0,t2=0; while(strcmp(temp,"+")!=0) {t1=t1*10+find(temp); scanf("%s",&temp); } scanf("%s",&temp); while(strcmp(temp,"=")!=0) {t2=t2*10+find(temp); scanf("%s",&temp); } if (t1==0 && t2==0) break; else printf("%d ",t1+t2); } return 0; }
原文地址:https://www.cnblogs.com/jianrenguo/p/6489564.html