简单模拟,输出格式有坑。
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
.
Problem: PAT-A 1082 Read Number in Chinese
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 |
Analysis
给一个最多九位的整数,用汉语拼音表示该数字,简单模拟。需要注意 0 的输出,当遇到 0 的时候做标记,直至遇到非 0 数时再输出 ling。测试点好像有一个输入数据是 0,所以对 0 的位置也要判断。另外测试点并不完全严谨,比如 100,000,000 不用严格输出 yi Yi,输出 yi Yi Wan 并不影响。在输出至第 4 位或第 8 位的时候无论当前位是不是 0,都要输出 Wan 或 Yi。
遇到的坑: 个位的 “” 并不是空的,会导致格式错误。
Code
1 |
|
Tsukkomi
格式错误给我整懵了,改了半天寻思空格也没搁错啊…… 万万想不到被 “” 卡了。这题以前好像在蓝桥杯的 OJ 上写过,测试也是不严谨,不过这次确实是写得最简洁的一次了。