题解 | A + B
A + B
https://www.nowcoder.com/practice/5fb3548802bb4a13a10c2e53a6fbfdd9
#include <iostream>
#include<map>
#include<sstream>
using namespace std;
int main() {
map<string,int>m1;
m1["one"]=1;m1["two"]=2;m1["three"]=3;m1["four"]=4;m1["five"]=5;m1["six"]=6;
m1["seven"]=7;m1["eight"]=8;m1["nine"]=9;m1["zero"]=0;
string a,b,c;
while (getline(cin,c)) { // 注意 while 处理多个 case
istringstream stream1(c);
string tmp;
int a=0,b=0;
while(stream1>>tmp){
if(tmp!="+"){
a=a*10+m1[tmp];
}else break;
}
while(stream1>>tmp){
if(tmp!="="){
b=b*10+m1[tmp];
}else break;
}
if(a==0&&b==0)return 0;
printf("%d\n",a+b);
}
}
// 64 位输出请用 printf("%lld")
查看13道真题和解析