#include<iostream>
#include<strstream>
#include<string>
#include<map>
using namespace std;
int main()
{
char line[256];
int ans;
map<string,int>entod;
entod[string("zero")]=0;
entod[string("one")]=1;
entod[string("two")]=2;
entod[string("three")]=3;
entod[string("four")]=4;
entod[string("five")]=5;
entod[string("six")]=6;
entod[string("seven")]=7;
entod[string("eight")]=8;
entod[string("nine")]=9;
entod[string("ten")]=10;
entod[string("eleven")]=11;
entod[string("twelve")]=12;
entod[string("thirteen")]=13;
entod[string("fourteen")]=14;
entod[string("fifteen")]=15;
entod[string("sixteen")]=16;
entod[string("seventeen")]=17;
entod[string("eighteen")]=18;
entod[string("nineteen")]=19;
entod[string("twenty")]=20;
entod[string("thirty")]=30;
entod[string("forty")]=40;
entod[string("fifty")]=50;
entod[string("sixty")]=60;
entod[string("seventy")]=70;
entod[string("eighty")]=80;
entod[string("ninety")]=90;
while(cin.getline(line,256)){
int len=strlen(line);
if(len==0){
continue;
}
istrstream istr(line,len);
string en;
int add=0;
ans=0;
while(istr>>en){
if(en=="negative"){
cout<<"-";
}
if(en=="hundred"){
add*=100;
}
if(en=="thousand"){
ans+=add*1000;
add=0;
}
if(en=="million"){
ans+=add;
ans*=100000;
add=0;
}
add+=entod[en];
}
ans+=add;
cout<<ans<<endl;
}
return 0;
}
poj 2121.Inglish-Number Translator
最新推荐文章于 2018-04-03 00:24:01 发布