PAT1082. Read Number in Chinese

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
思路:比较麻烦的题 需要考虑多种情况。  四个四个进行处理 并且需要考虑到0的情况

 1 #include<cstdio>
 2 #include<cstring>
 3 char data[10][6]=
 4 {
 5     "ling",
 6     "yi",
 7     "er",
 8     "san",
 9     "si",
10     "wu",
11     "liu",
12     "qi",
13     "ba",
14     "jiu"
15 };
16 char sig[6][9]=
17 {
18     "Shi",
19     "Bai",
20     "Qian",
21     "Wan",
22     "Yi"
23 };
24 char sen[11];
25 int main(int argc, char *argv[])
26 {
27     scanf("%s",sen);
28     //注意处理0的问题
29     int len=strlen(sen);
30     int left=0,right=len-1;
31     if(sen[0]==‘-‘)
32     {
33         left++;
34         printf("Fu");
35     }
36     while(left+4<=right)
37     {
38         right-=4;
39     }
40     while(left<len)
41     {
42         bool accumalte=false;
43         bool Isprint=false;
44         while(left<=right)
45         {
46             if(left>0&&sen[left]==‘0‘)
47             {
48                 accumalte=true;
49             }
50             else
51             {
52                  if(accumalte)
53                  {
54                     accumalte=false;
55                     printf(" ling");
56                 }
57                 if(left>0)
58                    printf(" ");
59                   printf("%s",data[sen[left]-‘0‘]);
60                   Isprint=true;
61                   if(left!=right)
62                         printf(" %s",sig[right-left-1]);
63             }
64             left++;
65         }
66         if(Isprint&&right!=len-1)
67         {
68             printf(" %s",sig[(len-right-1)/4+2]);
69         }
70         right+=4;
71     }
72     putchar(‘\n‘);
73     return 0;
74 }

时间: 2024-10-09 18:38:03

PAT1082. Read Number in Chinese的相关文章

PAT 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 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

1082. Read Number in Chinese (25)【字符串处理】——PAT (Advanced Level) Practise

题目信息 1082. Read Number in Chinese (25) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B 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

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 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 B

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 read it in the traditional Chinese way. Output Fufirst if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai si Shi wu Wan li

1082. Read Number in Chinese (25)

题目如下: 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 b

Read Number in Chinese (25)

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

PAT (Advanced Level) 1082. Read Number in Chinese (25)

模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std;

PAT 1082. Read Number in Chinese

#include <cstdio> #include <cstdlib> #include <string> #include <vector> #include <algorithm> using namespace std; const char* d2cn[] = {"ling", "yi", "er", "san", "si", "

【PAT甲级】1082 Read Number in Chinese (25 分)

题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int num[17];string united[17]={"","yi","er","san&qu