题意:
中文题。。。。(水题)
解题思路:
利用字符串hash或map可求
注意:
无
#include <stdio.h>
#include <map>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <ctype.h>
using namespace std;
map<string,int> mp;
char str1[50];
int num1,num2;
void prepro(int len){
char word[50];
int wlen = 0;
int i = 0;
num1 = num2 = 0;
bool flag = false;
while(i<len){
if(isalpha(str1[i])){
word[wlen++] = str1[i];
}
else {
word[wlen] = 0;
if(wlen){
if(!flag){
num1 = num1*10 + mp[word];
}
else{
num2 = num2*10 + mp[word];
}
wlen = 0;
}
if(str1[i]=='+'){
flag = true;
}
}
++i;
}
}
int main(){
mp["zero"] = 0; mp["four"] = 4; mp["eight"] = 8;
mp["one"] = 1; mp["five"] = 5; mp["nine"] = 9;
mp["two"] = 2; mp["six"] = 6;
mp["three"] = 3; mp["seven"] = 7;
while(gets(str1)){
int len = (int)strlen(str1);
prepro(len);
if(num1==0&&num2==0)break;
printf("%d\n",num1+num2);
}
return 0;
}