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:

  1. -123456789

Sample Output 1:

  1. Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu

Sample Input 2:

  1. 100800

Sample Output 2:

  1. yi Shi Wan ling ba Bai
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<string.h>
  4. using namespace std;
  5. int num[] = {}, pt;
  6. void num2arr(int N){
  7. pt = ;
  8. do{
  9. num[pt++] = N % ;
  10. N = N / ;
  11. }while(N != );
  12. }
  13. char strNum[][] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
  14. char duan[][] = {"", "Shi", "Bai", "Qian"};
  15. char prt[][];
  16. int main(){
  17. int N, neg = , len = ;
  18. scanf("%d", &N);
  19. if(N < ){
  20. neg = -;
  21. N = N * -;
  22. }
  23. num2arr(N);
  24. if(neg == -){
  25. strcpy(prt[len++], "Fu");
  26. }
  27. int zeroTag = , wanTag = ;
  28. if(N == ){
  29. printf("ling");
  30. return ;
  31. }
  32. for(int i = pt - ; i>= ; i--){
  33. if(i == ){
  34. strcpy(prt[len++], strNum[num[i]]);
  35. strcpy(prt[len++], "Yi");
  36. }else if(num[i] == ){
  37. zeroTag = ;
  38. }else if(num[i] != ){
  39. if(i > && i < ){
  40. wanTag = ;
  41. }
  42. if(zeroTag == ){
  43. zeroTag = ;
  44. strcpy(prt[len++], strNum[]);
  45. }
  46. strcpy(prt[len++], strNum[num[i]]);
  47. if(i % != )
  48. strcpy(prt[len++], duan[i % ]);
  49. }
  50. if(i == && wanTag == ){
  51. strcpy(prt[len++], "Wan");
  52. }
  53. }
  54. for(int i = ; i < len; i++){
  55. if(i == len - )
  56. printf("%s", prt[i]);
  57. else printf("%s ", prt[i]);
  58. }
  59. cin >> N;
  60. return ;
  61. }

总结:

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. 基于DDD的.NET开发框架ABP实例,多租户 (Saas)应用程序,采用.NET MVC, Angularjs, EntityFramework-介绍

    介绍 基于ABPZERO的多租户 (Saas)应用程序,采用ASP.NET MVC, Angularjs-介绍 ASP.NET Boilerplate作为应用程序框架. ASP.NET MVC和ASP ...

  2. Object-Oriented(一)创建对象

    自用备忘笔记 前言 虽然可以使用 Object 和对象字面量创建对象,但是如果要创建大量相似的对象又显得麻烦.为解决这个问题,人们开始使用工厂模式的变种. 工厂模式 function person(n ...

  3. webvirtmgr-重命名kvm虚拟机的名称

    之前部署了Webvirtmgr平台管理kvm虚拟机,由于虚拟机在创建时名称是顺便起的,后续在虚拟机上部署了部分业务.为了便于管理,最好将虚拟机的名称重置下. 现在说下如何修改kvm中虚拟机的名称: 比 ...

  4. junit-test

    一.题目简介: 用单元测试junit4测试calculator类的加减乘除四种方法,来初步学习junit4的学习方法. 二.源码的github链接  :https://github.com/weare ...

  5. js/jquery禁止页面回退

    $(function() { //防止页面后退 history.pushState(null, null, document.URL); window.addEventListener('popsta ...

  6. 在XShell中使用sz和rz命令下载和上传文件

    借助XShell,使用linux命令sz可以很方便的将服务器上的文件下载到本地,使用rz命令则是把本地文件上传到服务器 工具/原料   XShell CentOS 6.5 使用sz下载文件   1 输 ...

  7. PAT 1061 判断题

    https://pintia.cn/problem-sets/994805260223102976/problems/994805268817231872 判断题的评判很简单,本题就要求你写个简单的程 ...

  8. js原生常用事件event

    onblur 元素失去焦点: onchange用户改变域的内容: onclick鼠标点击对象: onerror当加载图片时发生错误: onfocus 元素获得焦点: onkeypress某个键盘的键被 ...

  9. hive视图

    简化复杂的查询 员工好.姓名.月薪.年薪.在一个emp表中; 部门名称在dept的表中;并未年薪起了一个名字annlsal 查询视图 视图是一个虚表,是不存数据的

  10. Linux基础学习(5)--文本编辑器Vim

    第五章——文本编辑器Vim 一. Vim常用操作 1.Vim简介:              Vim是一个功能强大的全屏幕文本编辑器,是Linux/UNIX上最常用的文本编辑器,它的作用是建立.编辑. ...