A+B

http://acm.hdu.edu.cn/showproblem.php?pid=1228

View Code
 1 #include <iostream>
 2 using namespace std;
 3 string  strnum[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
 4 int strToint(string str)
 5 {
 6     int i;
 7     for(i=0;i<10;i++)
 8     if(str==strnum[i])
 9     return i;
10 }
11 int sum;
12 bool Input()
13 {
14    string first,second;//表示输入数据,可以是字母或符号
15    int num1=0,num2=0;
16    cin>>first;
17    cin>>second;
18    if(second!="+")
19    {
20         num1=strToint(first)*10+strToint(second);
21         cin>>first;
22     }
23     else num1=strToint(first);
24     cin>>first;
25     cin>>second;
26     if(second!="=")
27     {
28         num2=strToint(first)*10+strToint(second);
29         cin>>second;
30     }
31     else num2=strToint(first);
32     sum=num1+num2;
33     if(!num1&&!num2)return false;
34     else return true;
35 
36 }
37 int main()
38 {
39     while(Input())
40     cout<<sum<<endl;
41     return 0;
42 }

遇到问题时不要慌张,仔细读题,不懂得再读几遍
题意理解透了,哪怕没有好方法,也要一点点的解决,

要有自己的思想

原文地址:https://www.cnblogs.com/yelan/p/2922849.html