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 思路:比较麻烦的题 需要考虑多种情况。 四个四个进行处理 并且需要考虑到0的情况
1 #include<cstdio> 2 #include<cstring> 3 char data[10][6]= 4 { 5 "ling", 6 "yi", 7 "er", 8 "san", 9 "si", 10 "wu", 11 "liu", 12 "qi", 13 "ba", 14 "jiu" 15 }; 16 char sig[6][9]= 17 { 18 "Shi", 19 "Bai", 20 "Qian", 21 "Wan", 22 "Yi" 23 }; 24 char sen[11]; 25 int main(int argc, char *argv[]) 26 { 27 scanf("%s",sen); 28 //注意处理0的问题 29 int len=strlen(sen); 30 int left=0,right=len-1; 31 if(sen[0]==‘-‘) 32 { 33 left++; 34 printf("Fu"); 35 } 36 while(left+4<=right) 37 { 38 right-=4; 39 } 40 while(left<len) 41 { 42 bool accumalte=false; 43 bool Isprint=false; 44 while(left<=right) 45 { 46 if(left>0&&sen[left]==‘0‘) 47 { 48 accumalte=true; 49 } 50 else 51 { 52 if(accumalte) 53 { 54 accumalte=false; 55 printf(" ling"); 56 } 57 if(left>0) 58 printf(" "); 59 printf("%s",data[sen[left]-‘0‘]); 60 Isprint=true; 61 if(left!=right) 62 printf(" %s",sig[right-left-1]); 63 } 64 left++; 65 } 66 if(Isprint&&right!=len-1) 67 { 68 printf(" %s",sig[(len-right-1)/4+2]); 69 } 70 right+=4; 71 } 72 putchar(‘\n‘); 73 return 0; 74 }
时间: 2024-10-09 18:38:03