好久沒做題,要做就做水題。。。。
用C++中的map映射下數字和字符串 其他就沒什麼了
[cpp] #include<map>
#include<iostream>
#include<string>
using namespace std;
map<string,int>m;
int main()
{
m["one"]=1;
m["two"]=2;
m["three"]=3;
m["four"]=4;
m["five"]=5;
m["six"]=6;
m["seven"]=7;
m["eight"]=8;
m["nine"]=9;
m["zero"]=0;
char s[15];
int a,b;
while(cin>>s)
{
a=b=0;
while(strcmp(s,"+"))
{
a=a*10+m[s];
cin>>s;
}
cin>>s;
while(strcmp(s,"="))
{
b=b*10+m[s];
cin>>s;
}
if(a==0&&b==0)break;
cout<<a+b<<endl;
}
return 0;
}
#include<map>
#include<iostream>
#include<string>
using namespace std;
map<string,int>m;
int main()
{
m["one"]=1;
m["two"]=2;
m["three"]=3;
m["four"]=4;
m["five"]=5;
m["six"]=6;
m["seven"]=7;
m["eight"]=8;
m["nine"]=9;
m["zero"]=0;
char s[15];
int a,b;
while(cin>>s)
{
a=b=0;
while(strcmp(s,"+"))
{
a=a*10+m[s];
cin>>s;
}
cin>>s;
while(strcmp(s,"="))
{
b=b*10+m[s];
cin>>s;
}
if(a==0&&b==0)break;
cout<<a+b<<endl;
}
return 0;
}