http://ac.jobdu.com/problem.php?pid=1010
#include <cstdio>
#include <sstream>
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string, int > Map;
int get(string s)
{
string a;
istringstream is(s);
int res = 0;
while (is >> a)
{
res = res * 10 + Map[a];
}
return res;
}
int main()
{
Map["zero"] = 0; Map["one"] = 1; Map["two"] = 2; Map["three"] = 3; Map["four"] = 4; Map["five"] = 5;
Map["six"] = 6; Map["seven"] = 7; Map["eight"] = 8; Map["nine"] = 9;
string a, b, line;
while (getline(cin,line))
{
int idx0 = line.find("+");
a = line.substr(0, idx0);
int idx1 = line.find("=");
b = line.substr(idx0 + 1, idx1-idx0-1);
int ax = get(a), bx = get(b);
if (ax == 0 && bx == 0) break;
cout << ax + bx << endl;
}
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-2161.html