-
题目描述:
-
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
-
输入:
-
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
-
输出:
-
对每个测试用例输出1行,即A+B的值.
-
样例输入:
-
one + two = three four + five six = zero seven + eight nine = zero + zero =
-
样例输出:
-
3 90 96
参考代码:
#include<iostream> #include<string> #include<map> using namespace std; int main() { //freopen("in.txt","r",stdin); map<string,int> ma; ma["zero"] = 0;ma["one"] = 1; ma["two"] = 2;ma["three"] = 3; ma["four"] = 4;ma["five"] = 5; ma["six"] = 6;ma["seven"] = 7; ma["eight"] = 8;ma["nine"] = 9; string s; int a, b, sum; cin>>s; while(1) { a = ma[s]; cin>>s; if(s != "+") { a = a*10 + ma[s]; cin>>s; } cin>>s; b = ma[s]; cin>>s; if(s != "=") { b = b*10 + ma[s]; cin>>s; } sum = a + b; if(sum == 0) return 0; cout<<sum<<endl; cin>>s; } return 0; }