题解 | #学英语#
学英语
http://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc
#include<iostream>
#include<vector>
using namespace std;
vector<string>ge={"zero", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "ninteen"};
vector<string>shi={"none", "ten", "twenty", "thirty", "forty", "fifty", "sixty",
"seventy", "eighty", "ninety"};
string getData(int num)
{
if(num>=0&&num<=19)
{
return ge[num];
}
else if(num>=20&&num<=99)
{
if(num%10==0)
{
return shi[num/10];
}
else
{
return shi[num/10]+" "+getData(num%10);
}
}
else if(num>=100&&num<=999)
{
if(num%100==0)
{
return ge[num/100]+" hundred";
}
else{
return getData(num/100)+" hundred and "+getData(num%100);
}
}
else if(num>=1000&&num<=999999)
{
if(num%1000==0)
{
return ge[num/1000]+" thousand";
}
else{
return getData(num/1000)+" thousand "+getData(num%1000);
}
}
else if(num>=1000000&&num<=999999999)
{
if(num%1000000==0)
{
return ge[num/1000000]+" million";
}
else{
return getData(num/1000000)+" million "+getData(num/1000%1000)+" thousand "+getData(num%1000);
}
}
else if(num>=1000000000){
if(num%1000000000==0)
return ge[num/1000000000]+" billion";
return getData(num/1000000000)+" billion "+getData(num%10000000/1000000)+" million "+getData(num%1000000/1000)+" thousand "+getData(num%1000);
}
}
int main()
{
int num;
while(cin>>num)
{
cout<<getData(num)<<endl;
}
return 0;
}