• A1082 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 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




     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 string Week[7]={
     5     "MON","TUE","WED","THU","FRI","SAT","SUN"
     6 };
     7 
     8 string num[10]={
     9     "ling","yi","er","san","si","wu","liu","qi","ba","jiu"
    10 };
    11 
    12 string wei[5]={
    13     "Shi","Bai","Qian","Wan","Yi"
    14 };
    15 
    16 
    17 
    18 
    19 int main(){
    20     
    21     string str;
    22     
    23     cin>>str;
    24     
    25     int len=str.size();
    26     
    27     int left=0,right=len-1;
    28     
    29     
    30     if(str[0]=='-')
    31     {
    32         left++;
    33         cout<<"Fu";
    34     }
    35     
    36     while(left+4<=right)   //注意等于号
    37             right-=4;
    38     
    39     
    40     while(left<len){
    41             
    42         bool flag=false;
    43         bool isPrint=false;
    44         
    45         while(left<=right){
    46         
    47             
    48             if(left>0&&str[left]=='0'){
    49                 flag=true;
    50             }else{
    51                 if(flag){
    52                     cout<<" ling";
    53                     flag=false;
    54                 }
    55                 isPrint=true;
    56                 
    57                 if(left>0)cout<<" ";  //注意格式空格
    58                 cout<<num[str[left]-'0'];
    59                 
    60                 if(left!=right)
    61                     cout<<" "<<wei[right-left-1];
    62                     
    63             }
    64             
    65             left++;    
    66         }
    67         
    68         
    69         if(isPrint==true&&right!=len-1){
    70             cout<<" "<<wei[(len-1-right)/4+2];
    71         }
    72             
    73         
    74         right+=4;
    75         
    76         
    77     }
    78     
    79     
    80     
    81     return 0;
    82 } 
    
    

     

    
    
  • 相关阅读:
    链表数据-PHP的实现
    关于go的init函数
    socket小计
    很随笔
    go获取当前项目下所有依赖包
    关于synergy的问题
    二叉树的最大路径和
    大数求和
    重载<<运算符第二个参数必须加上const
    表达式求值
  • 原文地址:https://www.cnblogs.com/moranzju/p/11090197.html
Copyright © 2020-2023  润新知