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. Swarm基于多主机容器网络 - overlay networks 梳理

    前面介绍了Docker管理工具-Swarm部署记录,下面重点说下Swarm基于多主机容器通信的覆盖网络 在Docker版本1.12之后swarm模式原生支持覆盖网络(overlay networks) ...

  2. Gerrit日常维护记录

    Gerrit代码审核工具是个好东西,尤其是在和Gitlab和Jenkins对接后,在代码控制方面有着无与伦比的优势. 在公司线上部署了一套Gerrit系统,在日常运维中,使用了很多gerrit命令,在 ...

  3. 理解Vue 2.5的Diff算法

    DOM"天生就慢",所以前端各大框架都提供了对DOM操作进行优化的办法,Angular中的是脏值检查,React首先提出了Virtual Dom,Vue2.0也加入了Virtual ...

  4. 11.14 Daily Scrum

    实现推荐菜谱时遇到问题,这个功能要和数据库和服务器有关,所以暂时放在一边,可能在beta版本实现. 部分成员已经完成基本任务,进行完善.   Today's Task Tomorrow's Task ...

  5. OneZero第七周第一次站立会议(2016.5.9)

    1. 时间: 12:15--12:25  共计10分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  6. 关于supervisor 的使用以及配置

    首先我个人认为,用python实现的supervisor使用了守护进程这个概念去实现一个包裹进程的概念. 他可以帮助你的进程完成失效重启,日志记录,确保在线,关机自启动等一系列的功能. 当使用supe ...

  7. javaIO缓冲区

    java中IO类分类. 图来自网络 缓冲区:应用程序在内存中开辟的一个空间.用来放置需要被写入或写出的数据. 使用缓冲区的 优点:使得应用程序操作磁盘(或者说是与磁盘的通信)的次数降低,提高应用程序的 ...

  8. linux shell << 注释多行

    #!/bin/bash #script name: a.sh #author: aaron <<EOF echo "line 1" echo "line 2& ...

  9. CSS等高布局的7种方式

    前面的话 等高布局是指子元素在父元素中高度相等的布局方式.等高布局的实现包括伪等高和真等高,伪等高只是看上去等高而已,真等高是实实在在的等高.本文将介绍边框模拟.负margin这两种伪等高以及tabl ...

  10. Linux系统——程序员跳槽必备

    相信在看这篇文章的你,曾经或者现在是否跳槽呢,在北上广一线城市,你是否还在挣着那可怜巴巴的工资,过着拮据生活呢?但是自己想跳槽,却没有一技之长或者是自己的技术找工作太难了,那么我建议你学习下linux ...