题解 | #A + B#
A + B
https://www.nowcoder.com/practice/5fb3548802bb4a13a10c2e53a6fbfdd9
#include<iostream>//很多人想复杂了,这个题格式都是固定的,直接一个个输入就行了 #include<string> using namespace std; int strToNum(string str) { if (str == "zero") return 0; else if (str == "one") return 1; else if (str == "two") return 2; else if (str == "three") return 3; else if (str == "four") return 4; else if (str == "five") return 5; else if (str == "six") return 6; else if (str == "seven") return 7; else if (str == "eight") return 8; else return 9; } int main() { string str; while (cin >> str) { int a = strToNum(str); cin >> str; while (str != "+") { a *= 10; a += strToNum(str); cin >> str; } int b = 0; cin >> str; while (str != "=") { b *= 10; b += strToNum(str); cin >> str; } cout << a + b << endl; } }