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
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int num[] = {}, pt;
void num2arr(int N){
pt = ;
do{
num[pt++] = N % ;
N = N / ;
}while(N != );
}
char strNum[][] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
char duan[][] = {"", "Shi", "Bai", "Qian"};
char prt[][];
int main(){
int N, neg = , len = ;
scanf("%d", &N);
if(N < ){
neg = -;
N = N * -;
}
num2arr(N);
if(neg == -){
strcpy(prt[len++], "Fu");
}
int zeroTag = , wanTag = ;
if(N == ){
printf("ling");
return ;
}
for(int i = pt - ; i>= ; i--){
if(i == ){
strcpy(prt[len++], strNum[num[i]]);
strcpy(prt[len++], "Yi");
}else if(num[i] == ){
zeroTag = ;
}else if(num[i] != ){
if(i > && i < ){
wanTag = ;
}
if(zeroTag == ){
zeroTag = ;
strcpy(prt[len++], strNum[]);
}
strcpy(prt[len++], strNum[num[i]]);
if(i % != )
strcpy(prt[len++], duan[i % ]);
}
if(i == && wanTag == ){
strcpy(prt[len++], "Wan");
}
}
for(int i = ; i < len; i++){
if(i == len - )
printf("%s", prt[i]);
else printf("%s ", prt[i]);
}
cin >> N;
return ;
}

总结:

1、属于字符串处理问题,我写的不太好,写完后才发现问题,于是只能修修补补勉强过了测试点。由于题目所给的数字最多才到亿,可以分成三段(如果够分的话),亿、万、个,分别处理。对于每一段,分别读数(几千几百几十几),读完每一段再分别输出‘亿’、‘万’。

2、对于零的处理:由于多个零可能按一个零读(1001),也可能不读(1000),这个需要额外注意。可以采取这样的办法:遇到0时不要立马读出,而是设置一个zero标志,该符号表示是否已经有了未读的0,在遇到一个非0的数字时,再检查zero标志看看是否有0未读,如果有则先读0,再读这个非0数字,再修改zero标志。 另外,在读完一段数字时,需要把zero标志置为没有未读0(如 1,1230,1234)。

3、注意N = 0时的处理。注意万段全为0时不可读“万”,且要读一个0(1,0000,1234)。

4、不好直接输出的,可以先拷贝到prt数组中,之后统一输出。

A1082. Read Number in Chinese的更多相关文章

  1. A1082 Read Number in Chinese (25)(25 分)

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

  2. A1082 Read Number in Chinese (25 分)

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

  3. PAT甲级——A1082 Read Number in Chinese

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

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

  5. PAT1082:Read Number in Chinese

    1082. Read Number in Chinese (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

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

  7. pat1082. Read Number in Chinese (25)

    1082. Read Number in Chinese (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

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

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

随机推荐

  1. 《坦克世界》1.0+:使用 CPU 优化的图形和物理丰富用户体验

    本文以<坦克世界>为例,介绍 Wargaming 使用 CPU 多核和 CPU 单指令多数据 (SIMD) 功能显著提升游戏沉浸式体验的创新方法.我们以英特尔® 线程构建模块(英特尔® T ...

  2. linux内核分析第八次实验

    20135118 罗鹏越 本周学习的是linux内核中的进程调度,之前我们在操作系统中有讲解进程调度的分类,以及一些调度算法.而linux中的进程调度有所不同,首先老师讲解了进程调度和进程调度的时机, ...

  3. 剑指offer:数组中重复的数字

    题目描述: 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果输入长度 ...

  4. [Intellij IDEA]_eclipse项目导入

    http://www.cnblogs.com/lindp/p/4484390.html

  5. js数组的用法

    1.数组 - - 添加元素 arr.push('abc')  向数组尾部添加元素,返回值为数组的长度 arr.unshift('abc')  向数组头部添加元素,返回值为数组的长度 2.数组 - - ...

  6. mac安装sublime text 3,含注册码

    软件下载地址: https://www.sublimetext.com/3 注册码如下: —– BEGIN LICENSE —– TwitterInc 200 User License EA7E-89 ...

  7. PAT 甲级 1045 Favorite Color Stripe

    https://pintia.cn/problem-sets/994805342720868352/problems/994805437411475456 Eva is trying to make ...

  8. Resolved validation conflict with readonly

    /** * Bug绕过去方案WorkAround * Bug描述: * JQuery的Validation的和form的input元素设为readonly,一对不可调和的矛盾: * 一个设置为requ ...

  9. [微软官网]windows server 内存限制

    Memory Limits for Windows and Windows Server Releases https://docs.microsoft.com/zh-cn/windows/deskt ...

  10. 机器学习中的降维算法:ISOMAP & MDS

    参见:https://blog.csdn.net/Dark_Scope/article/details/53229427