数字转字符
1. 原文
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 |
2. 解析
数字转数组
1
2
3
4do{
num[idx++]=n%10;
n/=10;
}while(n!=0);数组转字符串
1
2
3
4if (i!=0&&(num[i]!=0||i==4||i==8)){
ans[t++]=shi[i];
}
ans[t++]=ge[num[i]];
3. AC代码
1 |
|