首页 > 其他 > 详细

1082. Read Number in Chinese (25)

时间:2015-12-06 12:49:55      阅读:219      评论:0      收藏:0      [点我收藏+]
屎一样的代码、、、、
做完这个题就不想考试了、、、

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

 
  1. #include <iostream>
  2. #include<string>
  3. #pragma warning(disable:4996)
  4. using namespace std;
  5. string num[11] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
  6. string str, temp;
  7. string danwei[] = {"Shi","Bai","Qian","Wan"};
  8. void Read4WeiNum(int n) {
  9. }
  10. int main(void) {
  11. // freopen("Text.txt", "r", stdin);
  12. /*while (true)
  13. {
  14. */
  15. cin >> str;
  16. /*if (str == "q")
  17. break;*/
  18. if (str[0] == ‘-‘)
  19. cout << "Fu ";
  20. bool flag = false;
  21. for (int i = 0; i < str.length(); i++) {
  22. if (flag == false && (str[i] == ‘0‘ || str[i] == ‘-‘)) {
  23. continue;
  24. }
  25. else {
  26. temp += str[i];
  27. flag = true;
  28. }
  29. }
  30. if (flag == false) {
  31. cout << "ling";
  32. return 0;
  33. }
  34. str = temp;
  35. if (str.length() == 9) {
  36. cout << num[str[0] - ‘0‘] << " " << "Yi";
  37. if (str[1] == ‘0‘&&str[2] != ‘0‘)
  38. cout << " ling";
  39. else if (str[1] == ‘0‘&&str[2] == ‘0‘);
  40. else
  41. cout << " " << num[str[1] - ‘0‘] << " Qian";
  42. if (str[2] == ‘0‘&&str[3] != ‘0‘)
  43. cout << " ling";
  44. else if (str[2] == ‘0‘&&str[3] == ‘0‘);
  45. else
  46. cout << " " << num[str[2] - ‘0‘] << " Bai";
  47. if (str[3] == ‘0‘&&str[4] != ‘0‘)
  48. cout << " ling";
  49. else if (str[3] == ‘0‘&&str[4] == ‘0‘);
  50. else
  51. cout << " " << num[str[3] - ‘0‘] << " Shi";
  52. if (str[4] != ‘0‘) {
  53. cout << " " << num[str[4] - ‘0‘];
  54. cout << " Wan";
  55. }
  56. if (str[5] == ‘0‘&&str[6] != ‘0‘)
  57. cout << " ling";
  58. else if (str[5] == ‘0‘&&str[6] == ‘0‘);
  59. else
  60. cout << " " << num[str[5] - ‘0‘] << " Qian";
  61. if (str[6] == ‘0‘&&str[7] != ‘0‘)
  62. cout << " ling";
  63. else if (str[6] == ‘0‘&&str[7] == ‘0‘);
  64. else
  65. cout << " " << num[str[6] - ‘0‘] << " Bai";
  66. if (str[7] == ‘0‘&&str[8] != ‘0‘)
  67. cout << " ling";
  68. else if (str[7] == ‘0‘&&str[8] == ‘0‘);
  69. else
  70. cout << " " << num[str[7] - ‘0‘] << " Shi";
  71. if (str[8] != ‘0‘)
  72. cout << " " << num[str[8] - ‘0‘];
  73. }
  74. else if (str.length() > 4) {
  75. if (str.length() == 8) {
  76. cout << num[str[0] - ‘0‘] << " Qian";
  77. if (str[1] != ‘0‘)
  78. cout << " " << num[str[1] - ‘0‘] << " Bai";
  79. else if (str[1] == ‘0‘&&str[2] != ‘0‘)
  80. cout << " ling";
  81. if (str[2] != ‘0‘)
  82. cout << " " << num[str[2] - ‘0‘] << " Shi";
  83. else if (str[2] == ‘0‘&&str[3] == ‘0‘);
  84. else
  85. cout << " ling";
  86. if (str[3] != ‘0‘)
  87. cout << " " << num[str[3] - ‘0‘];
  88. }
  89. else if (str.length() == 7) {
  90. cout << num[str[0] - ‘0‘] << " Bai";
  91. if (str[1] != ‘0‘)
  92. cout << " " << num[str[1] - ‘0‘] << " Shi";
  93. else if (str[1] == ‘0‘&&str[2] != ‘0‘)
  94. cout << " ling";
  95. if (str[2] != ‘0‘)
  96. cout << " " << num[str[2] - ‘0‘];
  97. }
  98. else if (str.length() == 6) {
  99. cout << num[str[0] - ‘0‘] << " Shi";
  100. if (str[1] != ‘0‘)
  101. cout << " " << num[str[1] - ‘0‘];
  102. }
  103. else if (str.length() == 5) {
  104. cout << num[str[0] - ‘0‘];
  105. }
  106. cout << " Wan";
  107. if (str[str.length() - 4] == ‘0‘&&str[str.length() - 3] != ‘0‘)
  108. cout << " ling";
  109. else if (str[str.length() - 4] == ‘0‘&&str[str.length() - 3] == ‘0‘);
  110. else
  111. cout << " " << num[str[str.length() - 4] - ‘0‘] << " Qian";
  112. if (str[str.length() - 3] == ‘0‘&&str[str.length() - 2] != ‘0‘)
  113. cout << " ling";
  114. else if (str[str.length() - 3] == ‘0‘&&str[str.length() - 2] == ‘0‘);
  115. else
  116. cout << " " << num[str[str.length() - 3] - ‘0‘] << " Bai";
  117. if (str[str.length() - 2] == ‘0‘&&str[str.length() - 1] != ‘0‘)
  118. cout << " ling";
  119. else if (str[str.length() - 2] == ‘0‘&&str[str.length() - 1] == ‘0‘);
  120. else
  121. cout << " " << num[str[str.length() - 2] - ‘0‘] << " Shi";
  122. if (str[str.length() - 1] != ‘0‘)
  123. cout << " " << num[str[str.length() - 1] - ‘0‘];
  124. }
  125. else {
  126. if (str.length() == 4) {
  127. cout << num[str[0] - ‘0‘] << " Qian";
  128. if (str[1] != ‘0‘)
  129. cout << " " << num[str[1] - ‘0‘] << " Bai";
  130. else if (str[1] == ‘0‘&&str[2] != ‘0‘)
  131. cout << " ling";
  132. if (str[2] != ‘0‘)
  133. cout << " " << num[str[2] - ‘0‘] << " Shi";
  134. else if (str[2] == ‘0‘&&str[3] == ‘0‘);
  135. else
  136. cout << " ling";
  137. if (str[3] != ‘0‘)
  138. cout << " " << num[str[3] - ‘0‘];
  139. }
  140. else if (str.length() == 3) {
  141. cout << num[str[0] - ‘0‘] << " Bai";
  142. if (str[1] != ‘0‘)
  143. cout << " " << num[str[1] - ‘0‘] << " Shi";
  144. else if (str[1] == ‘0‘&&str[2] != ‘0‘)
  145. cout << " ling";
  146. if (str[2] != ‘0‘)
  147. cout << " " << num[str[2] - ‘0‘];
  148. }
  149. else if (str.length() == 2) {
  150. cout << num[str[0] - ‘0‘] << " Shi";
  151. if (str[1] != ‘0‘)
  152. cout << " " << num[str[1] - ‘0‘];
  153. }
  154. else if (str.length() == 1) {
  155. cout << num[str[0] - ‘0‘];
  156. }
  157. }
  158. /*cout << endl;
  159. str = "";
  160. temp = "";
  161. }*/
  162. return 0;
  163. }





1082. Read Number in Chinese (25)

原文:http://www.cnblogs.com/zzandliz/p/5023261.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!