题解 | #学英语#
字典法
#include <bits/stdc++.h>
using namespace std;
int main(){
string a[]= {"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourtenn","fifteen","sixteen","seventeen", "eighteen", "nineteen"};
string b[]= {"","","twenty", "thirty", "forty", "fifty", "sixty","seventy", "eighty", "ninety"};
string c[]= {"","thousand","million","billion"};
long n;
int m,l;
string s,t,r;
cin>> n;
s= to_string(n);
m= (s.length()-1)/ 3;
l= s.length()% 3;
if(l!= 0)
for(int i= 0; i< 3-l; ++i)
t+= '0';
t+= s;
s.clear();
for(int i =m; i>= 0; --i){
for(int j=0; j< 3; ++j){
s+= t[j];
r+= t[j];
}
r= r.substr(1);
t= t.substr(3);
if(s[0]!= '0')
if( stoi(r)!= 0)
cout<< a[s[0]-'0']<< " hundred and ";
else
cout<< a[s[0]-'0']<< " hundred ";
if(s[1]>= '2')
if(s[2]- '0'!= 0)
cout<< b[ s[1]- '0' ]<< " "<< a[s[2]- '0' ]<< " ";
else
cout<< b[ s[1]- '0' ]<< " ";
else
cout<< a[ stoi(r) ]<< " ";
cout<< c[i]<< " ";
s.clear();
r.clear();
}
}


查看7道真题和解析