题解 | #A + B#
A + B
https://www.nowcoder.com/practice/5fb3548802bb4a13a10c2e53a6fbfdd9
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <sstream> #include <vector> using namespace std; int main() { map<string, int> m={{"zero",0},{"one",1},{"two",2},{"three",3},{"four",4},{"five",5},{"six",6},{"seven",7},{"eight",8},{"nine",9}}; string sz; while (getline(cin,sz)) { vector<string> v; char c[100]; strcpy(c, sz.c_str()); char *temp=strtok(c, " "); while(temp!=NULL) { v.push_back(temp); temp=strtok(NULL, " "); } vector<int> a; vector<int> b; bool flag=true; for(int i=0;i<v.size();i++) { if(v[i]=="+") { flag=false; continue; } if(v[i]=="=") { break; } if(flag) { a.push_back(m[v[i]]); } else { { b.push_back(m[v[i]]); } } } reverse(a.begin(), a.end()); reverse(b.begin(),b.end()); int a_r=0; for(int i=a.size()-1;i>=0;i--) { a_r+=a[i]*pow(10,i); } int b_r=0; for(int i=b.size()-1;i>=0;i--) { b_r+=b[i]*pow(10,i); } if(a_r==0&&b_r==0) { break; } else { cout<<a_r+b_r<<endl; } } } // 64 位输出请用 printf("%lld")