# PAT-A 真题 – 1082 Read Number in Chinese

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``

FuckFourStep函数返回的modify变量的含义是，判断处理的这四位是否全0，如果例如100000000应输出yi Yi，而不是yi Yi Wan。

``````#include <iostream>
#include <bits/stdc++.h>
using namespace std;

const string num_str[] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
const string q_str[]   = {"", "Shi", "Bai", "Qian"};
const string step[]    = {"", "Wan", "Yi"};

bool FuckFourStep(int & num, vector<string> & ans){
bool have_pre_zero = true, modify = false;
for(int i = 0; i < 4; i++){  //前四位
if(num == 0) break;  //如果是0了，停止
int bit = num % 10;
if(bit != 0){  //当前位不是0
ans.push_back(q_str[i]);  //记录数字
ans.push_back(num_str[bit]);//记录位
have_pre_zero = false;
modify = true;
}
else if(bit == 0){  //当前位是0
if(!have_pre_zero) ans.push_back(num_str[0]);  //无前导0，记录0
have_pre_zero = true;
}
num /= 10;
}
return modify;
}

int main(){
int num;
cin >> num;
if(num < 0){  //符号
cout << "Fu ";
num = -num;
}
vector<string> ans;
bool last_modify = false;
for(int i = 0; i < 3; i++){
if(num == 0) break;
if(last_modify) ans.push_back(step[i]);
last_modify = FuckFourStep(num, ans);
}
for(int i = ans.size() - 1; i >= 0; i--){
if(ans[i] == "") continue;
if(i != ans.size() - 1) cout << ' ';
cout << ans[i];
}
if(ans.size() == 0) cout << "ling";
cout << endl;
return 0;
}``````