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. Windows开发常用快捷键

    毕业后一直在从事Windows开发工作,掌握些常用的Windows快捷键可以大大的提升工作效率,同时还能秀一波操作.本文记录在工作中常用的Windows快捷键,以及VS常用快捷键.掌握了这些键盘操作, ...

  2. Docker-compose封装mysql并初始化数据以及redis

    一.概述 现有一台服务器,需要部署mysql和redis.其中mysql容器,需要在第一次启动时,执行sql文件. redis保持空数据即可. 关于Docker-compose的安装,请参考连接: h ...

  3. MySQL之四 存储引擎

    1.介绍 存储引擎MySQL中的"文件系统" MySQL体系结构 InnoDB存储引擎介绍 My1SAM 和InnoDB区别  mysql MariaDB [(none)]> ...

  4. Netty源码 reactor 模型

    翻阅源码时,我们会发现netty中很多方法的调用都是通过线程池的方式进行异步的调用, 这种  eventLoop.execute 方式的调用,实际上便是reactor线程.对应项目中使用广泛的NioE ...

  5. 从一个想法看 FreeBSD 是商业化还是学院派

    在某知名计算机网络论坛上我看到一个帖子,说自己想根据 FreeBSD 做一个移动的终端操作系统,就像安卓,苹果的 IOS 一样的. 逆向思维当初开发安卓的时候不可能没有考虑过 FreeBSD,因为无论 ...

  6. AES加密--适用于RC2、RC4和Blowfish

    package test; import java.security.GeneralSecurityException; import java.security.Key; import javax. ...

  7. 《进击吧!Blazor!》系列入门教程 第一章 7.图表

    <进击吧!Blazor!>是本人与张善友老师合作的Blazor零基础入门教程视频,此教程能让一个从未接触过Blazor的程序员掌握开发Blazor应用的能力. 视频地址:https://s ...

  8. golang实现已知三角形三点坐标,求三角形面积

    代码如下: func GetTriangleAreaByVector(x vector.Vector3,y vector.Vector3,z vector.Vector3) float64 { //根 ...

  9. SpringMVC请求映射handler源码解读

    请求映射源码 首先看一张请求完整流转图(这里感谢博客园上这位大神的图,博客地址我忘记了): 前台发送给后台的访问请求是如何找到对应的控制器映射并执行后续的后台操作呢,其核心为DispatcherSer ...

  10. 使用SignalR ASP.NET Core来简单实现一个后台实时推送数据给Echarts展示图表的功能

    什么是 SignalR ASP.NET Core ASP.NET Core SignalR 是一种开放源代码库,可简化将实时 web 功能添加到应用程序的功能. 实时 web 功能使服务器端代码可以立 ...