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. IOS 上架到App Store被拒的常见问题总结

    Guideline 2.3.3 - Performance - Accurate Metadata 2017年11月16日 上午12:52 发件人 Apple 2. 3 Performance: Ac ...

  2. C. Meme Problem

    链接 [http://codeforces.com/contest/1076/problem/C] 题意 a+b=d and a⋅b=d. 计算出a和b 分析 ab=a(d-a)=d aa-ad+d= ...

  3. 1013 B. And

    链接 [http://codeforces.com/contest/1013/problem/B] 题意 给你一个n和x,再给n个数,有一种操作用x&a[i]取代,a[i],问使其中至少两个数 ...

  4. 毕业设计心得与整理-APP-主题切换

    1.定义主体颜色: 在style自定义了三个属性: <item name="textLight">@android:color/white</item> & ...

  5. 申港集中运营平台Linux测试环境架构搭建

    架构图 服务一览 ESB安装 ESB全称为Enterprise Service Bus,即企业服务总线.ESB提供了网络中最基本的连接中枢,是构筑企业神经系统的必要元素.ESB的出现改变了传统的软件架 ...

  6. Server Tomcat v7.0 Server at libra failed to start

    https://stackoverflow.com/questions/13244233/server-tomcat-v7-0-server-at-localhost-failed-to-start- ...

  7. SQLSERVER case when 的学习

    sqlserver 查询时的CASE WHEN学习记录 ) as '任务数', RPATask_State as id, case RPATask_State when then '已接收' when ...

  8. 关于Laravel中使用response()方法调用json()返回数据unicode编码转换的问题解决

    在网上找了好久没有找到,之后一步一步测试,发现了Laravel还是很强大的,解决方案如下: public function response(){ // 返回json数据 $data = [ 'err ...

  9. Jquery ajax ajaxStart()和ajaxStop()加载前的优雅表现

    Jquery中当一个Ajax请求启动时,并且没有其他未完成的Ajax请求时,将调用ajaxStart()方法.同样,ajaxStop()方法则是在所有Ajax请求都完成时调用.这些方法的参数都是一个函 ...

  10. using 的三种使用方式

    using 关键字有两个主要用途: 作为指令:用于为命名空间创建别名或导入在其他命名空间中定义的类型. 作为语句:用于定义一个范围,在此范围的末尾将释放对象. 此外,使用 using 静态指令可定义一 ...