Numbers in English are written down in the following way (only numbers lessthan 109 are considered). Numberabc,def,ghi is written as "[abc] million[def] thousand [ghi]".Here "[xyz] " means the written down numberxyz .
In the written down number the part "[abc] million" is omitted ifabc = 0 , "[def] thousand" is omitted ifdef = 0 , and "[ghi] " is omitted if ghi = 0 . If the whole number is equal to0 it is written down as "zero".Note that words "million" and "thousand" are singulareven if the number of millions or thousands respectively is greater than one.
Numbers under one thousand are written down in the following way. The numberxyz is written as "[x] hundred and[yz] ”. ( If yz = 0 it should be only “[x] hundred”. Otherwise if y = 0 it should be only “[x] hundred and [z]”.) Here "[x] hundred and"is omitted ifx = 0 . Note that "hundred" is also always singular.
Numbers under 20 are written down as "zero", "one", "two", "three", "four", "five", "six","seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen","fourteen", "fifteen", "sixteen", "seventeen", "eighteen", and "nineteen"respectively. Numbers from20 to 99 are written down in the following way.Number xy is written as "[x0] [y] ", and numbers divisible by tenare written as "twenty", "thirty", "forty", "fifty", "sixty", "seventy","eighty", and "ninety" respectively.
For example, number 987,654,312 is written down as "nine hundred andeighty seven million six hundred and fifty four thousand three hundred and twelve",number100,000,037 as "one hundred million thirty seven", number 1,000as "one thousand". Note that "one" is never omitted for millions,thousands and hundreds.
Give you the written down words of a number, please give out the original number.
Input
Standard input will contain multiple test cases. The first line of the input is a single integerT (1 <=T <= 1900) which is the number of test cases. It will be followed by T consecutive test cases.
Each test case contains only one line consisting of a sequence of English words representing a number.
Output
For each line of the English words output the corresponding integer in a single line.You can assume that the integer is smaller than109.
Sample Input
3 one eleven one hundred and two
Sample Output
1 11 102
十 ten 百 hundred 千 thousand 万 ten thousand 十万 hundred thousand 百万 million 千万 ten million 十亿 billion
也就是说
thousand==1000
million==1000000
出现这两位了说明该分开存了。有兴趣可以试试吧中文数字变成阿拉伯数字的哈哈哈
#include<bits/stdc++.h>
using namespace std;
int numb(string a)
{
int k=0,i;
string b[9]={"one","two","three","four","five","six","seven","eight","nine"};
string c[9]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
string d[9]={"ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"} ;
if(a=="zero")k==0;
else
for(i=0;i<9;i++)
{
if(a==b[i])k=i+1;
else if(a==c[i])k=10+(i+1);
else if(a==d[i])k=10*(i+1);
}
return k;
}
int main()
{
int n,i,a,b,c;
string s;
string f;
scanf("%d",&n);
getchar();
while(n--)
{
getline(cin,s);
a=0;b=0;c=0;
s.push_back(' ');
for(i=0;i<s.size();i++)
{
if(s[i]==' ')
{
if(f=="hundred")
a=a*100;
else if (f=="thousand")
{b=a*1000;a=0;}
else if(f=="million")
{c=a*1000000;a=0;}
else {a=a+numb(f);}
f.clear();continue;}//f=shu(l);ss.push_back(l);l.clear();f.clear()}numb(f);ss.push_back(f);
f=f+s[i];
}
printf("%d\n",a+b+c);
}
}
#include<bits/stdc++.h>
using namespace std;
int numb(string a)
{
int k=0,i;
string b[9]={"one","two","three","four","five","six","seven","eight","nine"};
string c[9]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
string d[9]={"ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"} ;
if(a=="zero")k==0;
else
for(i=0;i<9;i++)
{
if(a==b[i])k=i+1;
else if(a==c[i])k=10+(i+1);
else if(a==d[i])k=10*(i+1);
}
return k;
}
int main()
{
int n,i,a,b,c;
string s;
string f;
scanf("%d",&n);
getchar();
while(n--)
{
getline(cin,s);
a=0;b=0;c=0;
s.push_back(' ');
for(i=0;i<s.size();i++)
{
if(s[i]==' ')
{
if(f=="hundred")
a=a*100;
else if (f=="thousand")
{b=a*1000;a=0;}
else if(f=="million")
{c=a*1000000;a=0;}
else {a=a+numb(f);}
f.clear();continue;}//f=shu(l);ss.push_back(l);l.clear();f.clear()}numb(f);ss.push_back(f);
f=f+s[i];
}
printf("%d\n",a+b+c);
}
}