标签:== logs clu math style 习惯 mat 输出 while
给定一个32为有符号整数(int类型),输出符合汉语习惯的读法,如10086 读作“一万零八十六”。
1 #include<iostream>
2 #include<string>
3 #include<math.h>
4 using namespace std;
5 int main()
6 {
7 string dw[]={"","十","百","千","万","十","百","千","亿","十"};
8 string sz[]={"零","一","二","三","四","五","六","七","八","九"};
9 string bc[20];
10 int n,i=0,j;
11 bool flag =false;
12 cin>>n; // 432
13 if(n<0)
14 cout<<"负";
15 n=abs(n);
16 while(n)
17 {
18 bc[i]=sz[n%10];
19 n/=10;
20 i++;
21 }
22 j=i-1;
23 for(--i;i>0;i--)
24 {
25 flag =false;
26 while(i>0&&(bc[i]=="零"&&bc[i-1]=="零") )
27 {
28 i--;
29 if(dw[j]=="万"||dw[j]=="亿")
30 cout<<dw[j];
31 j--;
32 flag=true;
33 }
34 if(i!=0)
35 cout<<bc[i];
36 if(flag!=true&&bc[i]!="零")
37 cout<<dw[j];
38 j--;
39 }
40 if(bc[0]!="零")
41 cout<<bc[0];
42 cout<<endl;
43 return 0;
44 }
标签:== logs clu math style 习惯 mat 输出 while
原文地址:http://www.cnblogs.com/fmonlyg/p/7307803.html