题解 | A + B
#include <bits/stdc++.h> using namespace std; string num[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; int stringToInt(string s) { for (int i = 0; i < 10; i++) { if (num[i] == s)return i; } return -1; } int realInt(string a) { int x = 0; while (a.find(' ') != a.size() - 1) { x *= 10; x += stringToInt(a.substr(0, a.find(' '))); a = a.substr(a.find(' ') + 1); } x *= 10; x += stringToInt(a.substr(0, a.find(' '))); return x; } int main() { string s; while (getline(cin, s)) { string a = s.substr(0, s.find('+')); string b = s.substr(s.find('+') + 2); b = b.substr(0, b.find('=')); int x = realInt(a), y = realInt(b); if(x==0&&y==0)break; cout<<x+y<<endl; } }
本题难度在于如何把int给抽出来,需要做大量实验去找index,然后得到的代码如上,整体难度很低