题目1010:A + B
#include<iostream>
#include<string>
using namespace std;
int see(string s)
{
if(!s.compare("zero")) return 0;
if(!s.compare("one")) return 1;
if(!s.compare("two")) return 2;
if(!s.compare("three")) return 3;
if(!s.compare("four")) return 4;
if(!s.compare("five")) return 5;
if(!s.compare("six")) return 6;
if(!s.compare("seven")) return 7;
if(!s.compare("eight")) return 8;
else
return 9;
}
int main()
{
string a;
int num1,num2,key1,key2;//key1是指数字的十位,key2是指个位
//num1是指第一个加数 num2是指第二个加数
while(1)
{
num1=num2=key1=key2=0;
cin>>a;
key1=see(a);
cin>>a;
if(a=="+")
{
num1=key1;
cin>>a;
key1=see(a);
cin>>a;
if(a=="=")
{
num2=key1;
}
else
{
key2=see(a);
if(key1!=0)
{
num2=key1*10+key2;
}
else
{
num2=key2;
}
cin>>a;//此处要过滤掉=号
}
}
else
{
key2=see(a);
if(key1!=0)
{
num1=key1*10+key2;
}
else
{
num1=key2;
}
cin>>a;//此处为加号
cin>>a;
key1=see(a);
cin>>a;
if(a=="=")
{
num2=key1;
}
else
{
key2=see(a);
if(key1!=0)
{
num2=key1*10+key2;
}
else
{
num2=key2;
}
cin>>a;//此处要过滤掉=号
}
}
if(num1==0 && num2==0) break;
else
{
cout<<num1+num2<<endl;;
}
}
return 0;
}