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
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
using namespace std;
int main() {
string str;
cin >> str;
string s[11] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
string st[4] = { "Qian","","Shi","Bai" };
int sl = str.size();
string out;
for (int i = 0; i < sl; i++) {
if (str[i] == '-') out += "Fu ";
else {
int tmp = str[i] - '0';
if (tmp != 0) {
out += s[tmp];
out += " ";
}
else {
if (str[i + 1] != '0' && i != sl - 1) {
out += s[tmp];
out += " ";
}
}
if ((sl - i) == 9) out += "Yi ";
else if ((sl - i) == 5) out += "Wan ";
else {
if (tmp != 0) {
out += st[(sl - i) % 4];
if (i != sl - 1) out += " ";
}
}
}
}
string::iterator it = out.end() - 1;
out.erase(it);
cout << out;
return 0;
}