//4_7_12: Inglish-Number Translator 英语转数字 POJ2121 ZOJ2311
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char word[32][10] = {"zero","one","two","three","four","five","six","seven","eight","nine",
"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen",
"seventeen","eighteen","nineteen","twenty","thirty","forty","fifty",
"sixty","seventy","eighty","ninety","hundred","thousand","million","negative"};
int main()
{
char enter,str[10];
int i,num,neg;
while(1)
{
num = 0;
neg = 0;
while(1)
{
if(scanf("%s%c",str,&enter) == EOF) return 0;
for(i = 0;i < 32;i ++)
if(strcmp(word[i],str) == 0) break;
if(i >= 0 && i <=20 ) num += i;
else if(i >= 21 && i <= 27) num += (i - 18) * 10;
else if(i == 28) num = num % 100 * 100 + (num / 100) * 100;
else if(i == 29) num = num % 1000 * 1000 + (num / 1000) * 1000;
else if(i == 30) num = num % 1000000 * 1000000 + (num / 1000000) * 1000000;
else neg = 1;
if(enter == '\n')
{
if(neg == 1) printf("%d\n",-num);
else printf("%d\n",num);
break;
}
}
}
return 0;
}
/*测试结果:通过检测
six
6
negative seven hundred twenty nine
-729
one million one hundred one
1000101
eight hundred fourteen thousand twenty two
814022
^Z
请按任意键继续. . .
*/
POJ2121 ZOJ2311 Inglish-Number Translator
最新推荐文章于 2019-05-03 10:25:00 发布