PAT1082. Read Number in Chinese (25)
来源:互联网 发布:windows update更新慢 编辑:程序博客网 时间:2024/05/21 01:28
http://pat.zju.edu.cn/contests/pat-a-practise/1082
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 <string>#include <vector>#include <iostream>using namespace std;int main(){string a[] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};string b[] = {"", "Shi", "Bai", "Qian", "Wan", "Shi", "Bai", "Qian", "Yi"};vector<string> res;vector<int> digit;int num, e;cin >> num;if (num == 0){cout << "ling";return 0;} else if (num < 0){cout << "Fu ";num = -num;}while (num != 0){digit.push_back(num%10);num /= 10;}for (e=0; e<digit.size() && digit[e]==0; ++ e) {}if (e == 8){cout << a[digit[e]] << " Yi";return 0;}for (int i = e; i < digit.size(); ++ i){if (i!=0 && (digit[i]!=0 || i==4 || i==8)){res.push_back( b[i] );}res.push_back(a[ digit[i] ]);}for (int i = res.size()-1; i >= 0; -- i){if (i != res.size()-1){cout << " ";}int cnt = 0;while (i>=0 && res[i]=="ling"){-- i;++ cnt;}if (cnt!=0 && res[i]!="Wan"){cout << "ling ";}cout << res[i];}return 0;}
- PAT1082. Read Number in Chinese (25)
- pat1082 Read Number in Chinese
- Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese (25)
- pat 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese(25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 1002.Read Number in Chinese (25)
- A1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 【PAT】1082. Read Number in Chinese (25)
- bootstrap中固定table的表头
- 【状态压缩·二】Hiho9_Hihocoder
- Application类
- poj解题报告——1032
- UVA 107 The Cat in the Hat (数论)
- PAT1082. Read Number in Chinese (25)
- 了解JavaScript
- Enumeration和Iterator遍历集合类
- 去掉标题栏、信息栏和实现全屏
- IOS 帝国背后的神话故事
- SQLite应用实例
- POJ--1128--Frame Stacking【拓扑排序】
- 《Java并发编程实战》---并发编程带来的风险
- 分解正整数成质因数