1082 Read Number in Chinese (25 分)  

Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu. Note: zero (ling) must be handled correctly according to the Chinese tradition. For example, 100800 is yi Shi Wan ling ba Bai.

Input Specification:

Each input file contains one test case, which gives an integer with no more than 9 digits.

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Output Specification:

For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.

Sample Input 1:

-123456789 

Sample Output 1:

Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu 

Sample Input 2:

100800 

Sample Output 2:

yi Shi Wan ling ba Bai




 1 #include<bits/stdc++.h>
 2 using namespace std;  3 
 4 string Week[7]={  5     "MON","TUE","WED","THU","FRI","SAT","SUN"
 6 };  7 
 8 string num[10]={  9     "ling","yi","er","san","si","wu","liu","qi","ba","jiu"
10 }; 11 
12 string wei[5]={ 13     "Shi","Bai","Qian","Wan","Yi"
14 }; 15 
16 
17 
18 
19 int main(){ 20     
21     string str; 22     
23     cin>>str; 24     
25     int len=str.size(); 26     
27     int left=0,right=len-1; 28     
29     
30     if(str[0]=='-') 31  { 32         left++; 33         cout<<"Fu"; 34  } 35     
36     while(left+4<=right) //注意等于号 37             right-=4; 38     
39     
40     while(left<len){ 41             
42         bool flag=false; 43         bool isPrint=false; 44         
45         while(left<=right){ 46         
47             
48             if(left>0&&str[left]=='0'){ 49                 flag=true; 50             }else{ 51                 if(flag){ 52                     cout<<" ling"; 53                     flag=false; 54  } 55                 isPrint=true; 56                 
57                 if(left>0)cout<<" "; //注意格式空格 58                 cout<<num[str[left]-'0']; 59                 
60                 if(left!=right) 61                     cout<<" "<<wei[right-left-1]; 62                     
63  } 64             
65             left++; 66  } 67         
68         
69         if(isPrint==true&&right!=len-1){ 70             cout<<" "<<wei[(len-1-right)/4+2]; 71  } 72             
73         
74         right+=4; 75         
76         
77  } 78     
79     
80     
81     return 0; 82 } 

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄