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:
1 |
-123456789 |
Sample Output 1:
1 |
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu |
Sample Input 2:
1 |
100800 |
Sample Output 2:
1 |
yi Shi Wan ling ba Bai |
水题一道……
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#include<stdio.h> #include<string.h> int main() { char digit[10][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}, base[5][6]={" Qian"," Ge"," Shi"," Bai"},special[3][5]={""," Wan"," Yi"},buf[11]; int flag=0,i,n,current,zero,zero_pos; gets(buf); n=strlen(buf); i=0; if(buf[0]=='-') { printf("Fu"); flag=1; i=1; } if(n==1) { printf("%s\n",digit[buf[i]-'0']); return 0; } while(i<n) { if(buf[i]!='0') { if(flag) { printf(" "); } else { flag=1; } current=(n-i-1)/4; if(zero==1&&zero_pos==current) { printf("%s ",digit[0]); zero=0; } printf("%s",digit[buf[i]-'0']); if((n-i)%4!=1) { printf("%s",base[(n-i)%4]); } } else { zero_pos=(n-i-1)/4; zero=1; } if((n-i)%4==1&&(n-i-1)/4==current) { printf("%s",special[(n-i)/4]); } i++; } printf("\n"); } |