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