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. windows下docker启动.net core mvc随手记

    docker基本命令: 查看当前的版本docker--version查看本地所有镜像:docker images查看当前正在运行的所有容器docker ps停止某个容器:docker stop 容器I ...

  2. dpkg:错误:正在解析文件 '/var/lib/dpkg/updates/0014' 第 0 行附近:在字段名 #padding 中有换行符问题的解决方法

    解决方案如下: sudo rm /var/lib/dpkg/updates/* sudo apt-get update python@ubuntu:~/Desktop/_Welcome_.jpg.ex ...

  3. Centos7下关于系统用户密码规则-运维笔记

    针对Centos7下的系统用户的密码规则复杂度的设置,处于安全考虑,说明如下: 一.设置密码规则 1)密码长度.有效期 /etc/login.defs文件是当创建用户时的一些规划,比如创建用户时,是否 ...

  4. Spring RPC 入门学习(1)-HelloWorld入门

    Spring搭建RPC环境 第一,下载所需要的jar包,下载地址:https://yunpan.cn/cPErQeANrSMyB (提取码:63e5),见下图: 第二,新建动态WebProject,把 ...

  5. 2017-2018-2 1723《程序设计与数据结构》实验四 & 实验五 & 课程总结 总结

    作业地址 实验四作业:https://edu.cnblogs.com/campus/besti/CS-IMIS-1723/homework/1943 提交情况如图: 实验五作业:https://edu ...

  6. 语音笔记:MFCC

    一,传统语音识别体系结构 二,MFCC特征提取 MFCC(Mel-frequency cepstral coefficients):梅尔频率倒谱系数.梅尔频率是基于人耳听觉特性提出来的, 它与Hz频率 ...

  7. 结对项目 Pair Project

    结对项目 Pair Project 一人编程,一人操作,共同检查. 源码 https://github.com/dpch16303/test/blob/master/%E5%AE%9E%E8%B7%B ...

  8. vuejs基础

    **### 数据与方法 // 我们的数据对象 var data = { a: 1 } // 该对象被加入到一个 Vue 实例中 var vm = new Vue({ data: data }) // ...

  9. 自定义组件的 v-model

    Vue.component('base-checkbox', { model: { prop: 'checked', event: 'change' }, props: { checked: Bool ...

  10. zlib 简单封装

    下列代码用于压缩和解压字符串,使用标准库string.实现了对zlib的简单封装. #pragma once #include <boost/noncopyable.hpp> #inclu ...