http://acm.hdu.edu.cn/showproblem.php?pid=1228
分析:
我只是想练习一下map的用法,不然又忘了。。。
代码:
//hdu 1228
#include <iostream>
#include <stdio.h>
#include <map>
#include <string.h>
#include <string>
using namespace std;
map<string,int> d;
void init()
{
d["zero"]=0; d["one"]=1; d["two"]=2; d["three"]=3;
d["four"]=4; d["five"]=5; d["six"]=6; d["seven"]=7;
d["eight"]=8; d["nine"]=9;;
}
int deal(string s)
{
int num=0;
string word="";
for(int i=0;i<s.length();i++){
if(s[i]==' '){
if(i==s.length()-1){
num +=d[word];
return num;
}
else{
num =d[word]*10;
word="" ;
}
}
else
word +=s[i];
}
}
int main()
{
init();
string str;
string str1,str2;
int num1,num2;
while(getline(cin,str)){
int i=0;
str1="",str2="";
while(str[i]!='+') str1 +=str[i++];
i++;
while(str[i]!='=') str2 +=str[i++];
num1=deal(str1);
num2=deal(str2);
if(!num1 && (!num2)) break;
printf("%d\n",num1+num2);
}
return 0;
}