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

题意:

  给出一个数字,然后输出汉语读法。

思路:

  模拟。(注意特例0的输出)

Code:

 1 #include <bits/stdc++.h>
2
3 using namespace std;
4
5 int main() {
6 string str;
7 cin >> str;
8 if (stoi(str) == 0) {
9 cout << "ling" << endl;
10 return 0;
11 }
12 stack<string> ans;
13 bool isNegative = false;
14 if (str[0] == '-') {
15 str = str.substr(1);
16 isNegative = true;
17 }
18 int index = str.length() - 1;
19 string dummy[4] = {"+", "Shi", "Bai", "Qian"};
20 string numInCn[10] = {"ling", "yi", "er", "san", "si",
21 "wu", "liu", "qi", "ba", "jiu"};
22 while (index >= 0) {
23 bool notZero = false;
24 for (int i = 0; i < 4 && index >= 0; ++i, --index) {
25 if (str[index] == '0' && !notZero)
26 continue;
27 else {
28 if (str[index] == '0') {
29 ans.push(numInCn[str[index] - '0']);
30 } else {
31 if (i != 0) ans.push(dummy[i]);
32 ans.push(numInCn[str[index] - '0']);
33 }
34 notZero = true;
35 }
36 }
37 notZero = false;
38 if (index >= 0) ans.push("Wan");
39 for (int i = 0; i < 4 && index >= 0; ++i, --index) {
40 if (str[index] == '0' && !notZero)
41 continue;
42 else {
43 if (str[index] == '0') {
44 ans.push(numInCn[str[index] - '0']);
45 } else {
46 if (i != 0) ans.push(dummy[i]);
47 ans.push(numInCn[str[index] - '0']);
48 }
49 notZero = true;
50 }
51 }
52 if (index >= 0) {
53 ans.push("Yi");
54 ans.push(numInCn[str[index] - '0']);
55 --index;
56 }
57 }
58 if (isNegative) {
59 cout << "Fu";
60 while (!ans.empty()) {
61 cout << " " << ans.top();
62 ans.pop();
63 }
64 } else {
65 cout << ans.top();
66 ans.pop();
67 while (!ans.empty()) {
68 cout << " " << ans.top();
69 ans.pop();
70 }
71 }
72
73 return 0;
74 }

1082 Read Number in Chinese的更多相关文章

  1. 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 ...

  2. PAT 1082 Read Number in Chinese[难]

    1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed to ...

  3. 1082. Read Number in Chinese (25)

    题目如下: Given an integer with no more than 9 digits, you are supposed to read it in the traditional Ch ...

  4. PTA (Advanced Level)1082.Read Number in Chinese

    Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...

  5. 1082. Read Number in Chinese (25)-字符串处理

    题意就是给出9位以内的数字,按照汉子的读法读出来. 读法请看下方的几个例子: 5 0505 0505 伍亿零伍佰零伍万零伍佰零伍 5 5050 5050 伍亿伍仟零伍拾万伍仟零伍拾  (原本我以为这个 ...

  6. 1082 Read Number in Chinese (25分)

    // 1082.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <string> #include <vecto ...

  7. PAT (Advanced Level) 1082. Read Number in Chinese (25)

    模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  8. PAT 1082. Read Number in Chinese

    #include <cstdio> #include <cstdlib> #include <string> #include <vector> #in ...

  9. 【PAT甲级】1082 Read Number in Chinese (25 分)

    题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...

随机推荐

  1. python进阶(9)多线程

    什么是线程? 线程也叫轻量级进程,是操作系统能够进行运算调度的最小单位,它被包涵在进程之中,是进程中的实际运作单位.线程自己不拥有系统资源,只拥有一点儿在运行中必不可少的资源,但它可与同属一个进程的其 ...

  2. C#正则实现匹配一块代码段

    最近项目,生成聚合网关,但是生成的网关文件中,存在着不必要的代码段,比如一个类A,类B等 之前一直使用手动删除,这么做劳民伤财,浪费时间,考虑使用正则写一个工具实现自动删除. 正则写法: string ...

  3. 剑指 Offer 42. 连续子数组的最大和 + 动态规划

    剑指 Offer 42. 连续子数组的最大和 题目链接 状态定义: 设动态规划列表 \(dp\) ,\(dp[i]\) 代表以元素 \(4nums[i]\) 为结尾的连续子数组最大和. 为何定义最大和 ...

  4. WEBAPI 的调用方式

    示例是调用谷歌短网址的API. 1. HttpClient方式 public static async void DoAsyncPost() { DateTime dateBegin = DateTi ...

  5. APICloud Avm.js跨端框架的优势

    AVM(Application-View-Model)是APICloud推出的一个跨端的高性能 JavaScript框架,更趋近于原生的编程体验,它提供简洁的模型来分离应用的用户界面.业务逻辑和数据模 ...

  6. 那些你不知道的DOU+投放技巧,以及常见的审核失败原因丨国仁网络

    作为小额付费投放工具,DOU+一直深受各大中小商家的青睐.虽然它的审核比较严格,但转化效果还是非常明显的. 近日,抖音发布重要公告:内容低质的视频将无法购买DOU+推广,并可能因违反平台规则导致无法观 ...

  7. GNS3通过“云”连接到虚拟机实验

    GNS3通过"云"连接到虚拟机实验并使用wireshark工具对数据分析 观看本文之前注意!!!!! 做这次实验,我所遇到的问题,会全部写在文章结尾,如果读者们遇到问题,可查看. ...

  8. MySQL按天备份二进制日志

    #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:guozhen.zhang     import MySQLdbimport timeimp ...

  9. MyBatis:当表字段名和实体类属性名不一致

    第一种解决方法:在sql中使用别名 <select id="getRoleList" resultType="com.ttpfx.domain.Role" ...

  10. 配置docker的pdflatex环境

    技术背景 Latex在文档撰写方面是不可或缺的工具,尤其是在写文章方面,是必须要用到的文字排版工具.但是latex的环境部署并不是一个特别人性化的操作,尤其是在各种不同的平台上操作是完全不一样的,还经 ...