0
点赞
收藏
分享

微信扫一扫

【PAT甲级-1082】题解

Star英 2022-03-11 阅读 50
#include<iostream>
#include<cstring>
using namespace std;
char upper[6][6] = {"Shi", "Bai", "Qian", "Wan", "Yi"};
char common[11][6] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
int main() {
    string str;
    cin >> str;
    int len = str.length();
    if(len == 1) {
    	cout << common[str[0] - '0'];
    	return 0;
	}
    int left = 0, right = len - 1;
    if(str[0] == '-') {
    	cout << "Fu";
    	left++;
	}
	while(left + 4 <= right) {
		right -= 4;
	}
	while(left < len) {
		bool flag = false;
		bool isPrint = false;
		while(left <= right) {
			if(str[left] == '0') flag = true;
			else {
				if(flag) {
					cout << " ling";
					flag = false;
				}
				if(left > 0) cout << ' ';
				cout << common[str[left] - '0'];
				isPrint = true;
				if(left != right) cout << ' ' << upper[right - left - 1];
			}
			left++;
		}
		if(isPrint && right != len -1) {
			cout << ' ' << upper[(len - 1 - right) / 4 + 2];
		}
		right += 4;
	}
    return 0;
}
举报

相关推荐

0 条评论