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:-123456789Sample Output 1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiuSample Input 2:
100800Sample Output 2:
yi Shi Wan ling ba Bai
#include <iostream>
#include<string>
#pragma warning(disable:4996)
using namespace std;
string num[11] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
string str, temp;
string danwei[] = {"Shi","Bai","Qian","Wan"};
void Read4WeiNum(int n) {
}
int main(void) {
// freopen("Text.txt", "r", stdin);
/*while (true)
{
*/
cin >> str;
/*if (str == "q")
break;*/
if (str[0] == ‘-‘)
cout << "Fu ";
bool flag = false;
for (int i = 0; i < str.length(); i++) {
if (flag == false && (str[i] == ‘0‘ || str[i] == ‘-‘)) {
continue;
}
else {
temp += str[i];
flag = true;
}
}
if (flag == false) {
cout << "ling";
return 0;
}
str = temp;
if (str.length() == 9) {
cout << num[str[0] - ‘0‘] << " " << "Yi";
if (str[1] == ‘0‘&&str[2] != ‘0‘)
cout << " ling";
else if (str[1] == ‘0‘&&str[2] == ‘0‘);
else
cout << " " << num[str[1] - ‘0‘] << " Qian";
if (str[2] == ‘0‘&&str[3] != ‘0‘)
cout << " ling";
else if (str[2] == ‘0‘&&str[3] == ‘0‘);
else
cout << " " << num[str[2] - ‘0‘] << " Bai";
if (str[3] == ‘0‘&&str[4] != ‘0‘)
cout << " ling";
else if (str[3] == ‘0‘&&str[4] == ‘0‘);
else
cout << " " << num[str[3] - ‘0‘] << " Shi";
if (str[4] != ‘0‘) {
cout << " " << num[str[4] - ‘0‘];
cout << " Wan";
}
if (str[5] == ‘0‘&&str[6] != ‘0‘)
cout << " ling";
else if (str[5] == ‘0‘&&str[6] == ‘0‘);
else
cout << " " << num[str[5] - ‘0‘] << " Qian";
if (str[6] == ‘0‘&&str[7] != ‘0‘)
cout << " ling";
else if (str[6] == ‘0‘&&str[7] == ‘0‘);
else
cout << " " << num[str[6] - ‘0‘] << " Bai";
if (str[7] == ‘0‘&&str[8] != ‘0‘)
cout << " ling";
else if (str[7] == ‘0‘&&str[8] == ‘0‘);
else
cout << " " << num[str[7] - ‘0‘] << " Shi";
if (str[8] != ‘0‘)
cout << " " << num[str[8] - ‘0‘];
}
else if (str.length() > 4) {
if (str.length() == 8) {
cout << num[str[0] - ‘0‘] << " Qian";
if (str[1] != ‘0‘)
cout << " " << num[str[1] - ‘0‘] << " Bai";
else if (str[1] == ‘0‘&&str[2] != ‘0‘)
cout << " ling";
if (str[2] != ‘0‘)
cout << " " << num[str[2] - ‘0‘] << " Shi";
else if (str[2] == ‘0‘&&str[3] == ‘0‘);
else
cout << " ling";
if (str[3] != ‘0‘)
cout << " " << num[str[3] - ‘0‘];
}
else if (str.length() == 7) {
cout << num[str[0] - ‘0‘] << " Bai";
if (str[1] != ‘0‘)
cout << " " << num[str[1] - ‘0‘] << " Shi";
else if (str[1] == ‘0‘&&str[2] != ‘0‘)
cout << " ling";
if (str[2] != ‘0‘)
cout << " " << num[str[2] - ‘0‘];
}
else if (str.length() == 6) {
cout << num[str[0] - ‘0‘] << " Shi";
if (str[1] != ‘0‘)
cout << " " << num[str[1] - ‘0‘];
}
else if (str.length() == 5) {
cout << num[str[0] - ‘0‘];
}
cout << " Wan";
if (str[str.length() - 4] == ‘0‘&&str[str.length() - 3] != ‘0‘)
cout << " ling";
else if (str[str.length() - 4] == ‘0‘&&str[str.length() - 3] == ‘0‘);
else
cout << " " << num[str[str.length() - 4] - ‘0‘] << " Qian";
if (str[str.length() - 3] == ‘0‘&&str[str.length() - 2] != ‘0‘)
cout << " ling";
else if (str[str.length() - 3] == ‘0‘&&str[str.length() - 2] == ‘0‘);
else
cout << " " << num[str[str.length() - 3] - ‘0‘] << " Bai";
if (str[str.length() - 2] == ‘0‘&&str[str.length() - 1] != ‘0‘)
cout << " ling";
else if (str[str.length() - 2] == ‘0‘&&str[str.length() - 1] == ‘0‘);
else
cout << " " << num[str[str.length() - 2] - ‘0‘] << " Shi";
if (str[str.length() - 1] != ‘0‘)
cout << " " << num[str[str.length() - 1] - ‘0‘];
}
else {
if (str.length() == 4) {
cout << num[str[0] - ‘0‘] << " Qian";
if (str[1] != ‘0‘)
cout << " " << num[str[1] - ‘0‘] << " Bai";
else if (str[1] == ‘0‘&&str[2] != ‘0‘)
cout << " ling";
if (str[2] != ‘0‘)
cout << " " << num[str[2] - ‘0‘] << " Shi";
else if (str[2] == ‘0‘&&str[3] == ‘0‘);
else
cout << " ling";
if (str[3] != ‘0‘)
cout << " " << num[str[3] - ‘0‘];
}
else if (str.length() == 3) {
cout << num[str[0] - ‘0‘] << " Bai";
if (str[1] != ‘0‘)
cout << " " << num[str[1] - ‘0‘] << " Shi";
else if (str[1] == ‘0‘&&str[2] != ‘0‘)
cout << " ling";
if (str[2] != ‘0‘)
cout << " " << num[str[2] - ‘0‘];
}
else if (str.length() == 2) {
cout << num[str[0] - ‘0‘] << " Shi";
if (str[1] != ‘0‘)
cout << " " << num[str[1] - ‘0‘];
}
else if (str.length() == 1) {
cout << num[str[0] - ‘0‘];
}
}
/*cout << endl;
str = "";
temp = "";
}*/
return 0;
}
1082. Read Number in Chinese (25)
原文:http://www.cnblogs.com/zzandliz/p/5023261.html