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, -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要正确处理。

//我一看见这个题就蒙了,完全没有思路。

代码来自:https://www.liuchuo.net/archives/2204

#include <iostream>
#include <string>
#include <vector>
using namespace std;
string num[] = { "ling","yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" };
string c[] = { "Ge","Shi", "Bai", "Qian", "Yi", "Wan" };
int J[] = {, , , , , , , , };
vector<string> res;
int main() {
int n;
cin >> n;
if (n == ) {
cout << "ling";
return ;
}
if (n < ) {
cout << "Fu ";
n = -n;
}
int part[];
part[]= n / ;//亿以上的
part[]= (n % ) / ;//千万级
part[] = n % ;//万级
bool zero = false; //是否在非零数字前输出合适的ling
int printCnt = ; //用于维护单词前没有空格,之后输入的单词都在前面加一个空格。
for (int i = ; i < ; i++) {
int temp = part[i]; //三个部分,每部分内部的命名规则都一样,都是X千X百X十X
for (int j = ; j >= ; j--) {
int curPos = - i * + j; //当前数字的位置
if (curPos >= ) continue; //最多九位数
int cur = (temp / J[j]) % ;//取出当前数字
if (cur != ) {
if (zero) {
printCnt++ == ? cout<<"ling" : cout<<" ling";
zero = false;
}
if (j == )
printCnt++ == ? cout << num[cur] : cout << ' ' << num[cur]; //在个位,直接输出
else
printCnt++ == ? cout << num[cur] << ' ' << c[j] : cout << ' ' << num[cur] << ' ' << c[j]; //在其他位,还要输出十百千
} else {
if (!zero&&j != && n / J[curPos] >= ) zero = true; //注意100020这样的情况
}
}
if (i != && part[i]>) cout << ' ' << c[i + ]; //处理完每部分之后,最后输出单位,Yi/Wan
}
return ;
}

//这个逻辑太难了。我是写不出来的,勉强看懂。

PAT 1082 Read Number in Chinese[难]的更多相关文章

  1. PAT 1082. Read Number in Chinese

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

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

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

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

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

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

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

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

  7. 1082 Read Number in Chinese

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

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

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

  9. 1082 Read Number in Chinese (25分)

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

随机推荐

  1. 如何正确理解javascript的模块化的

  2. Mike Gancarz:Linux/Unix设计思想

           Mike Gancarz是一位技术布道者. 他是Linux/Unix最基本的倡导者之中的一个,也是最早开发X Window System的先驱.他把一些在Unix/Linux社区里口口相 ...

  3. Linux,unix,cygwin,centeros下的tar压缩解压缩命令具体解释

    tar Examples:   tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.   tar -tvf ...

  4. [BestCoder Round #5] hdu 4956 Poor Hanamichi (数学题)

    Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. 设置Android应用程序横竖屏显示

    设置Android应用程序横竖屏显示有2中方式: 1.在mainfest中增加android:screenOrientation属性 <?xml version="1.0" ...

  6. 查看系统进程:ps

    ps命令用于查看系统进程,常见用法如下: [root@localhost ~]$ ps aux # 查看所有的进程 [root@localhost ~]$ ps aux | grep nginx # ...

  7. Windows 下安装 Python3

    可以使用两种方式安装 Python3,一种是直接去官网下载安装包,然后进行安装即可:另一种是通过安装 Anaconda 来安装 Python3, Anaconda 提供了 Python 的科学计算环境 ...

  8. EventBus 简单原理(一)

    EventBus 1.根据文章最前面所讲的EventBus使用步骤,首先我们需要定义一个消息事件类: public class MessageEvent { private String messag ...

  9. 关于C#我今天的六个小时

    嘿嘿,今天周六啦,我们是自由学习啦,于是还记得前几天纠结的事情,还有好多不太熟悉的题目那,于是今天就找出来练习下拉,而且这些题目在老师给我们复习时间也给我们讲解过啦,这样一来应该做起来还是容易点的啦, ...

  10. 今天是学习C#面向过程的最后的一天

    今天学习完啦面向过程,可能写法也就是那些,固定不变的,但是程序的写法就是由自己决定······ 今天学习了调用已经存在的方法,就是在.net  Framework 中存在的方法,具体今天提到的有这些, ...