浙大2005年研究生机试
此为模拟类型的题目。A+B
#include <iostream>
#include <string>
using namespace std;
int trans(string s){
if("one" == s) return 1;
else if("two" == s) return 2;
else if("three" == s) return 3;
else if("four" == s) return 4;
else if("five" == s) return 5;
else if("six" == s) return 6;
else if("seven" == s) return 7;
else if("eight" == s) return 8;
else if("nine" == s) return 9;
else return 0;
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("E:\\in.txt", "r", stdin);
#endif
string s;
while(cin>>s){
int a, b;
for(a=trans(s); cin>>s, s != "+"; a=a*10 + trans(s));
for(b=0; cin>>s, s!= "="; b=b*10 +trans(s));
int c = a+b;
if(c == 0)
break;
else
cout << c << endl;
}
return 0;
}
#include <stdio.h>
#include <string.h>
const int MAXSIZE = 20;
void turn(int & t, char str[]){
if(strcmp(str, "one") == 0){
t = 1;
}else if(strcmp(str, "two") == 0){
t = 2;
}else if(strcmp(str, "two") == 0){
t = 2;
}
else if(strcmp(str, "three") == 0){
t = 3;
}
else if(strcmp(str, "four") == 0){
t = 4;
}
else if(strcmp(str, "five") == 0){
t = 5;
}
else if(strcmp(str, "six") == 0){
t = 6;
}
else if(strcmp(str, "seven") == 0){
t = 7;
}
else if(strcmp(str, "eight") == 0){
t = 8;
}else if(strcmp(str, "nine") == 0){
t = 9;
}
else if(strcmp(str, "zero") == 0){
t = 0;
}
return ;
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("E:\\in.txt", "r", stdin);
#endif
char str[MAXSIZE];
while( scanf("%s" ,str) != EOF){
int a=0;
int t;
turn(t, str);
a = a*10 + t;
while(scanf("%s", str) && strcmp(str, "+") != 0){
turn(t, str);
a = a*10 + t;
}// read a
int b=0;
while(scanf("%s", str) && strcmp(str, "=") != 0){
turn(t, str);
b = b*10 + t;
}// read b
int c = a +b;
if(c != 0){
cout << a+b << endl;
}else{
break;
}
}//while
return 0;
}