http://ac.jobdu.com/problem.php?id=1010
浙大的这道考研上机题处理输入需要有些技巧,直观上应该是考察对C++类库的熟悉吧,尤其是map的使用。
”+“预示第一个操作数已经处理完毕,”=“预示第二个操作数处理完毕。
我的AC代码:
#include <iostream>
#include <map>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
int a, b;
string t;
map <string, int > m;
m["zero"] = 0, 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;
while(1)
{
a = b = 0;
while(cin >> t && t != "+") a = a * 10 + m[t];
while(cin >> t && t != "=") b = b * 10 + m[t];
if(!a && !b) break;
else printf("%d\n", a+b);
}
system("pause");
return 0;
}