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. Win7配置SVN详细步骤(服务器和客户端)

    下载并安装服务器端SVN  VisualSVN Server 下载并安装客户端SVN  TortoiseSVN 创建SVN库 在C盘创建文件夹MySVN(可自由命名),打开文件夹----右键Torto ...

  2. 超全面的JavaWeb笔记day20<监听器&国际化>

    JavaWeb监听器 三大组件: l Servlet l Listener l Filter Listener:监听器 1. 初次相见:AWT 2. 二次相见:SAX 监听器: l 它是一个接口,内容 ...

  3. ch6-定制数据对象(打包代码和数据)

    为了看出数据属于哪个选手,教练向各个选手的数据文件中添加了标识数据:选手全名,出生日期,计时数据. 例如:sarah文件的数据更新为: Sarah Sweeney,2002-6-17,2:58,2.5 ...

  4. 打开Linux ftp服务,如:vsftpd: unrecognized service

    打开Linux ftp服务,如:vsftpd: unrecognized service   [root@BZXXDBS02 ~]# service vsftpd start vsftpd: unre ...

  5. piblog 0.1

    搭建开发环境首先,确认系统安装的Python版本是2.7.x. $ python --version Python 然后,安装开发Web App需要的第三方库:$ sudo pip install j ...

  6. KVO的用法、底层实现原理

    KVO的用法 KVO也就是key-value-observing(即键值观察),利用一个key来找到某个属性并监听其值得改变.用法如下: 添加观察者 在观察者中实现监听方法,observeValueF ...

  7. Runtime应用(二)使用对象关联为分类增加属性(每个对象的属性互不干扰)

    一.对象的关联方法有 1. void objc_setAssociatedObject(id object, const void *key, id value,objc_AssociationPol ...

  8. linux 允许mysql用户远程访问

    搭建服务器..怎么导入数据库?  直接来个用户吧 数据库名字(已存在): table 创建mysql新用户,并指定数据库,允许远程访问 mysql用户: test mysql用户密码: test666 ...

  9. CRUX下实现进程隐藏(3)

    通过一个内核模块拦截文件系统的回调函数来实现进程隐藏. VFS(Virtual File System)是Linux在实际文件系统(如ext3,ext4,vfat等)上抽象出的一个文件系统模型,简单来 ...

  10. Linux系统内核main函数执行之前

    1.linux是一个操作系统在机器加电后,需要从硬件通过一个引导程序加载os kernel,那么在os kernel的main函数运行之前,都发生了什么呢? (1)引导BIOS(存储在ROM芯片中,R ...