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.
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
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
int main(){
string unit[]={" ","Shi","Bai","Qian"};
string number[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int val;
scanf("%d",&val);
if(val==0){
printf("ling\n");
return 0;
}
int flag;
if(val<0){
flag=1;
val*=-1;
}else{
flag=0;
}
vector<int>vt[3];
int tmp=val;
int i=0;
while(tmp!=0){
vt[i].push_back(tmp%10);
tmp=tmp/10;
if(vt[i].size()==4){
i++;
}
}
vector<string>result;
vector<int>t;
if(vt[2].size()>0){
t=vt[2];
result.push_back(number[t[0]]);
result.push_back("Yi");
}
if(vt[1].size()>0){
t=vt[1];
int size = t.size();
int i=size-1;
int index=0;
while(t[i]==0){
index=1;
i--;
}
int index1=0;
for(;i>=0;i--){
if(t[i]==0){
index1=1;
continue;
}
if(index==1||index1==1){
result.push_back("ling");
index=0;
index1=0;
}
result.push_back(number[t[i]]);
if(i!=0)
result.push_back(unit[i]);
}
if(index==0){
result.push_back("Wan");
}
}
if(vt[0].size()>0){
t=vt[0];
int size = t.size();
int i=size-1;
int index=0;
while(t[i]==0){
index=1;
i--;
}
int index1=0;
for(;i>=0;i--){
if(t[i]==0){
index1=1;
continue;
}
if(index==1||index1==1){
result.push_back("ling");
index=0;
index1=0;
}
result.push_back(number[t[i]]);
if(i!=0)
result.push_back(unit[i]);
}
}
int size=result.size();
if(flag==1){
cout<<"Fu ";
}
cout<<result[0];
for(i=1;i<size;i++){
cout<<' '<<result[i];
}
cout<<endl;
return 0;
}

浙公网安备 33010602011771号