zoukankan      html  css  js  c++  java
  • 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 } 
    
    

     

    
    
  • 相关阅读:
    Mysql存储过程详解
    自动化测试——人人都可自制“呼死你”
    Apktool(1)——Apktool的安装
    Apktool(2)——使用前必须知道的apk知识
    写博是种心情
    webpack使用tree shaking的问题。及关于UglifyJs不支持ES6的解决方案。
    angular2 笔记
    angular2 content projection
    angular2aotwebpack 生产环境下编译angular2
    ionic2配置问题集
  • 原文地址:https://www.cnblogs.com/moranzju/p/11090197.html
Copyright © 2011-2022 走看看