1082. Read Number in Chinese (25)

╰半橙微兮° 2022-05-29 13:46 225阅读 0赞

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. #include<stdio.h>
  2. #include<stdlib.h>
  3. char a[10][5]={"Shi","Bai","Qian","Wan","Shi","Bai","Qian","Yi"};
  4. char c[11][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
  5. int b[15],m,flag=0;
  6. int main()
  7. {
  8. int i,j,n,k,t,l=0;
  9. scanf("%d",&n);
  10. m=abs(n);
  11. if(n<0)
  12. {
  13. printf("Fu ");
  14. }
  15. if(m==0)
  16. {
  17. printf("ling");
  18. }
  19. while(m>0)
  20. {
  21. b[l++]=m%10;
  22. m/=10;
  23. }
  24. for(i=l-1;i>=0;i--)
  25. {
  26. for(j=i;j>=0;j--)
  27. if(b[j]!=0)
  28. break;
  29. if(j<0)
  30. break;
  31. if(b[i]==0)
  32. {
  33. if(i>3)
  34. {
  35. for(j=i;j>3;j--)
  36. {
  37. if(b[j]!=0)
  38. break;
  39. }
  40. i=j+1;
  41. if(j<=3)
  42. {
  43. printf(" Wan");
  44. }
  45. else
  46. {
  47. printf(" ling");
  48. }
  49. }
  50. else
  51. {
  52. for(j=i;j>=0;j--)
  53. {
  54. if(b[j]!=0)
  55. {
  56. break;
  57. }
  58. }
  59. if(j>=0)
  60. {
  61. printf(" ling");
  62. }
  63. i=j+1;
  64. }
  65. continue;
  66. }
  67. if(i==l-1)
  68. {
  69. if(i-1>=0)
  70. printf("%s %s",c[b[i]],a[i-1]);
  71. else
  72. printf("%s",c[b[i]]);
  73. }
  74. else
  75. {
  76. if(i-1>=0)
  77. printf(" %s %s",c[b[i]],a[i-1]);
  78. else
  79. printf(" %s",c[b[i]]);
  80. }
  81. }
  82. return 0;
  83. }

发表评论

表情:
评论列表 (有 0 条评论,225人围观)

还没有评论,来说两句吧...

相关阅读