您好,欢迎来到爱够旅游网。
搜索
您的当前位置:首页1082 Read Number in Chinese (25 分)

1082 Read Number in Chinese (25 分)

来源:爱够旅游网

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, -1234567 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:

-1234567

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;
}

 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务