标签:rip names algo card 规范 str std sample mes
1234567009
shi er yi san qian si bai wu shi liu wan qi qian ling jiu
题意很简单,耐心分析,然后模拟就完事了。
可以发现将每四位分成一组,中间用亿、万连接起来比较简便。
将分好的四位一组的数每一位分别判断一下
十位为1时根据百位的情况有shi、yi shi两种可能,比如1011是:yi qian ling shi yi,而不是yi qian ling yi shi yi
注意 ling 和 空格 的输出
不确定的读音可以去这个在线网站查一下:
http://www.nicetool.net/embed/number_to_chinese.html
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <string> 5 #include <math.h> 6 #include <algorithm> 7 #include <vector> 8 #include <stack> 9 #include <queue> 10 #include <set> 11 #include <map> 12 #include <sstream> 13 const int INF=0x3f3f3f3f; 14 typedef long long LL; 15 const int mod=1e9+7; 16 const int maxn=1e4+10; 17 using namespace std; 18 19 map<int,string> mp; 20 21 int main() 22 { 23 #ifdef DEBUG 24 freopen("sample.txt","r",stdin); 25 #endif 26 27 mp[0]="ling";mp[1]="yi"; mp[2]="er"; mp[3]="san"; mp[4]="si"; mp[5]="wu"; 28 mp[6]="liu"; mp[7]="qi"; mp[8]="ba"; mp[9]="jiu"; mp[10]="shi"; 29 30 int n; 31 cin>>n; 32 int t,a,b,c,d; 33 int f1=0,f2=0; 34 if(n>=100000000)//处理"亿"之前 35 { 36 f1=1; 37 t=n/100000000; 38 a=t/10; 39 b=t%10; 40 if(a) 41 { 42 if(a>1) cout<<mp[a]<<" "; 43 cout<<"shi"; 44 if(b) cout<<" "<<mp[b]; 45 } 46 else cout<<mp[b]; 47 cout<<" "<<"yi"; 48 if(n%100000000) cout<<" ";//如果后面不为0,分隔 49 } 50 if(n%100000000>=10000)//处理"万"之前 51 { 52 f2=1; 53 t=(n%100000000)/10000; 54 a=t/1000; 55 b=t%1000/100; 56 c=t%100/10; 57 d=t%10; 58 if(a) 59 { 60 cout<<mp[a]<<" qian"; 61 if(b||c||d) cout<<" "; 62 } 63 else if(f1) cout<<"ling "; 64 if(b) 65 { 66 cout<<mp[b]<<" bai"; 67 if(c||d) cout<<" "; 68 } 69 else 70 { 71 if((a&&c)||(a&&d)) cout<<"ling "; 72 } 73 if(c) 74 { 75 if(c>1) cout<<mp[c]<<" "; 76 cout<<"shi"; 77 if(d) cout<<" "; 78 } 79 else 80 { 81 if(b&&d) cout<<"ling "; 82 } 83 if(d) cout<<mp[d]; 84 cout<<" "<<"wan"; 85 if(n%10000) cout<<" ";//如果后面不为0,分隔 86 } 87 if(n%10000) 88 { 89 t=(n%10000); 90 a=t/1000; 91 b=t%1000/100; 92 c=t%100/10; 93 d=t%10; 94 if(a) 95 { 96 cout<<mp[a]<<" qian"; 97 if(b||c||d) cout<<" "; 98 } 99 else if(f2) cout<<"ling "; 100 if(b) 101 { 102 cout<<mp[b]<<" bai"; 103 if(c||d) cout<<" "; 104 } 105 else 106 { 107 if((a&&c)||(a&&d)) cout<<"ling "; 108 } 109 if(c) 110 { 111 if(c>1) cout<<mp[c]<<" "; 112 cout<<"shi"; 113 if(d) cout<<" "; 114 } 115 else 116 { 117 if(b&&d) cout<<"ling "; 118 } 119 if(d) cout<<mp[d]; 120 } 121 cout<<endl; 122 123 return 0; 124 }
我写的有点麻烦,推荐一篇写法简洁的博客:
https://blog.csdn.net/weixin_43804406/article/details/104126113
-
标签:rip names algo card 规范 str std sample mes
原文地址:https://www.cnblogs.com/jiamian/p/12286004.html