给你一个数字,输出它的英文单词
预处理特殊数字和基本数字
然后就特判有没有1e6以上,有没有1e3以上,……
有就去掉后面的6位数或者3位数,然后用扔子函数里当3位数处理了
我连forty和ninety都写错。。。。。。。。= =
1 #include<bits/stdc++.h> 2 using namespace std; 3 string w[20],v[20],p[10]; 4 int n; 5 void init(){ 6 w[1]="one"; 7 w[2]="two"; 8 w[3]="three"; 9 w[4]="four"; 10 w[5]="five"; 11 w[6]="six"; 12 w[7]="seven"; 13 w[8]="eight"; 14 w[9]="nine"; 15 w[10]="ten"; 16 w[11]="eleven"; 17 w[12]="twelve"; 18 w[13]="thirteen"; 19 w[14]="fourteen"; 20 w[15]="fifteen"; 21 w[16]="sixteen"; 22 w[17]="seventeen"; 23 w[18]="eighteen"; 24 w[19]="nineteen"; 25 v[2]="twenty"; 26 v[3]="thirty"; 27 v[4]="forty"; 28 v[5]="fifty"; 29 v[6]="sixty"; 30 v[7]="seventy"; 31 v[8]="eighty"; 32 v[9]="ninety"; 33 p[0]="and"; 34 p[1]="hundred"; 35 p[2]="thousand"; 36 p[3]="million"; 37 p[4]="billion"; 38 return; 39 } 40 void Work(int x){ 41 if(x/100){ 42 cout<<w[x/100]<<" "<<p[1]<<" "; 43 x%=100; 44 if(x>0)cout<<p[0]<<" "; 45 } 46 if(x>0&&x<=19) { 47 cout<<w[x]<<" "; 48 return; 49 } 50 if(x==0)return; 51 cout<<v[x/10]<<" "; 52 x%=10; 53 if(x) cout<<w[x]<<" "; 54 return; 55 } 56 int main(){ 57 init(); 58 cin>>n; 59 if(n>=1000000){ 60 Work(n/1000000); 61 n%=1000000; 62 cout<<p[3]<<" "; 63 // if(n) printf("and "); 64 } 65 if(n>=1000){ 66 Work(n/1000); 67 n%=1000; 68 cout<<p[2]<<" "; 69 // if(n) printf("and "); 70 } 71 if(n>0){ 72 Work(n); 73 } 74 return 0; 75 }
标签:10,20,Work,1000000,HJ42,cout0,英语,1000 From: https://www.cnblogs.com/AlenaNuna/p/18393422