Given an integer with no more than 9 digits, you are supposed to read itin the traditional Chinese way. Output "Fu" first if it isnegative. For example, -123456789 is read as "Fu yi Yi er Qian sanBai si Shi wu Wan liu Qian qi Bai ba Shi jiu". Note: zero("ling") must be handled correctly according to the Chinesetradition. For example, 100800 is "yi Shi Wan ling ba Bai".
输入描述:
Each input file contains one test case, which gives an integer with no more than 9 digits.
输出描述:
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.
示例1
输入
-123456789
输出
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
// pat.cpp : 定义控制台应用程序的入口点。 //#include "stdafx.h" #include"stdio.h" #include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<vector> #include<deque> #include<math.h> using namespace std; typedef long long ll; string s; string un[2]={"Wan","Yi"}; string unit[5]={"Qian","","Shi","Bai"}; string number[10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; int i=0; int len; string ans=""; bool iszero(int in){ int last=in+4; for(;in<last;in++) if(s[in]!='0')return false; return true; } int main(){ //freopen("c://jin.txt","r",stdin); cin>>s; len=s.length(); if(s[0]=='-'){ans+="Fu ";i++;} int flag=0,f=0;; while(i<len){ int j=len-i; int n=s[i]-'0'; if(n!=0) {ans+=number[n];ans+=" "; if(j%4!=1)ans+=unit[j%4]+" "; flag=1;f=1; } else if(j%4!=1&&s[i+1]!='0'){ ans+=number[n]+" "; } if(j==5){ if(flag)ans+="Wan "; else{ while(i+1<len&&s[i+1]=='0')i++; if(i!=len-1)ans+="ling ";} flag=0;} else if(j==9){ if(flag) {ans+="Yi ";} else{ while(i+1<len&&s[i+1]=='0')i++; if(i!=len-1)ans+="ling "; } flag=0; } if(j==1){ if(f==0) ans+="ling";} i++; } while(ans[ans.length()-1]==' ')ans.erase(ans.end()-1); cout<<ans; //freopen("CON","r",stdin); //system("pause"); return 0; }