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
.
Each input file contains one test case, which gives an integer with no more than 9 digits.
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.
-123456789
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
100800
yi Shi Wan ling ba Bai
调试了半天,处理各种细节问题,详情看代码中的注释吧。注意:
1. PAT 已经不支持 gets(),会报错 error: 'gets' was not declared in this scope,需用cin.getline(s,长度)代替;
2. 注意100001234这种数的输出是一亿零一千二百三十四
#include
#include
#include
using namespace std;
int main()
{
//初始化
int f=0, length, t;
char s[11]={'*','*','*','*','*','*','*','*','*','*'}; //避免初始化0,影响判断
//用于位数的汉字表示,把空格和个位表示也存入数组,便于输出格式
char w[][11] = {" Yi"," Qian"," Bai"," Shi"," Wan"," Qian"," Bai"," Shi",""};
//用于数字的汉字表示,存成数组就不用switch选了
char n[][11] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
//PAT已经不支持gets(),会报错error: 'gets' was not declared in this scope
//gets(s);
cin.getline(s,11);
length = strlen(s);
//判断正负
if (s[0]=='-')
{
printf("Fu ");
f=1; //数据处理时,数据从下标1开始
}
t = length-f; //求除了负号以外的位数
for (int i=f; i