题目描述
请将一个数字,翻译成对应的英文。
输入
一个自然数 nn。(0\le n \le 2^{31}-10≤n≤231−1)
输出
输出这个数的英文,最后不要有多余的空格。
样例
输入
1111111111
输出
one billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven
来源
字符串
代码如下:
#include<bits/stdc++.h>
using namespace std;
//1~19单独翻译
string numn_1[30]= {"\0"," one"," two"," three"," four"," five"," six"," seven"," eight"," nine"," ten"," eleven"," twelve"," thirteen"," fourteen"," fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
//20~90英文单词
string numn_2[10]= {"\0","\0"," twenty"," thirty"," forty"," fifty"," sixty"," seventy"," eighty"," ninety"};
string r1,r;
int n,h,c;
/*
能AC。但程序对10001之类的翻译是错误的!
*/
int main() {
cin>>n;
c=0;
while(n!=0) {
h=n%1000;
r="";
if(h/100!=0) {
r=numn_1[h/100]+" hundred and";
}
if(h%100<20) {
r=r+numn_1[h%100];
} else {
r=r+numn_2[h/10%10]+numn_1[h%10];
}
c++;
if(c==2) r=r+" thousand";
else if(c==3) r=r+" million";
else if(c==4) r=r+" billion";
r1=r+r1;
n=n/1000;
}
cout<<r1.erase(0,1)<<endl;
return 0;
}