1+2=3

/*Problem A 

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)

Total Submission(s) : 8   Accepted Submission(s) : 6

Problem Description
 
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.


 


Input
 
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出. 


 


Output
 
对每个测试用例输出1行,即A+B的值.


 


Sample Input

one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
Sample Output

39096
 
*/
#include<iostream>
using namespace std;
char s[40];
char temp[11]={'z','o','t','t','f','f','s','s','e','n'}; 
int myth(int k)
{
    int ans=0;
    for(int j=0;j<11;j++)
    {
        if(s[k]=='t'&&s[k+1]=='w')
            ans=2;
        else if(s[k]=='t'&&s[k+1]=='h')
            ans=3;
        else if(s[k]=='s'&&s[k+1]=='i')
            ans=6;
        else if(s[k]=='s'&&s[k+1]=='e')
            ans=7;
        else if(s[k]=='f'&&s[k+1]=='o')
            ans=4;
        else if(s[k]=='f'&&s[k+1]=='i')
            ans=5;
        else if(temp[j]==s[k])
            ans=j;
    }
    return ans;
}
int main()
{
    while(1)
    {
        int ans1=0,ans2=0;
        cin.getline(s,40,'\n');
        int i=0;
         ans1 =myth(i);
        while(s[i]!=' ')
            i++;
        if(s[++i]=='+')
        {
            i+=2;
            ans2=myth(i);
        }
        else
        {
            ans1=ans1*10+myth(i);
            while(s[i]!=' ')
            i++;
            i=i+3;
            ans2=myth(i);
        }
        if(!ans1&&!ans2)
            break;
        while(s[i]!=' ')
            i++;
        i++;
        if(s[i]=='=')
            printf("%d\n",ans1+ans2);
        else
        {
            ans2=ans2*10+myth(i);
            printf("%d\n",ans1+ans2);
        }        
    }
    return 0;
}

 

posted @ 2012-11-16 23:07  myth_HG  阅读(260)  评论(0编辑  收藏  举报