A+B英文

/*

读入两个小于100的正整数A和B,计算A+B.

需要注意的是:A和B的每一位数字由对应的英文单词给出.

Iput

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

Output

 

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

  Sample Input

 

one + two =

three four + five six =

zero seven + eight nine =

zero + zero =

*/

#include<iostream>

#include<stdlib.h>

#include<stdio.h>

#include<string>

#include<math.h>

using namespace std;

int change(string a)

{

         if(a=="zero")

                   return 0;

         else if(a=="one")

                   return 1;

         else if(a=="two")

                   return 2;

         else if(a=="three")

                   return 3;

         else if(a=="four")

                   return 4;

         else if(a=="five")

                   return 5;

         else if(a=="six")

                   return 6;

         else if(a=="seven")

                   return 7;

         else if(a=="eight")

                   return 8;

         else

                   return 9;

}

int main()

{

         string a[10];

         int i,tag,num,e,ee,sum1,sum2,j;

         while(true)

         {

                   i=0;tag=0;num=0;e=0;ee=0;

                   do

                   {

                            cin>>a[i++];

                   }while(a[i-1]!="=");

                   sum1=0;sum2=0;

                   for(j=0;j<i;j++)

                   {

                            if((a[j]!="+")&&(tag==0))

                            {

                                     num=change(a[j]);

                                     sum1=sum1*pow(10.0,e*1.0)+num;

                                     e++;

                            }

                            if(a[j]=="+")

                            {

                                     tag=j;

                                     continue;

                            }

                            if((j>tag)&&(tag!=0))

                            {

                                     if(a[j]!="=")

                                     {

                                               num=change(a[j]);

                                               sum2=sum2*pow(10.0,1.0*ee)+num;

                                               ee++;

                                     }

 

                            }

                   }

                   if(sum1==0&&sum2==0)

                            break;

                   else

                            cout<<(sum1+sum2)<<endl;

         }

         return 0;

}

posted @ 2012-11-23 22:12  ♂咱說 ろ算  阅读(340)  评论(0编辑  收藏  举报