美文网首页
PAT 甲级1082 Read Number in Chines

PAT 甲级1082 Read Number in Chines

作者: Skittle丶 | 来源:发表于2020-10-29 18:58 被阅读0次

    说真的这道题按照算法笔记上写应该会比较简单,能完美避免末尾0的问题。但是我就是头铁,就是要从头到尾的进行处理,事实证明难是不难,就是要考虑的内容太多

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include<iostream>
    #include <string.h>
    using namespace std; 
    int main(){
        int start=0;
        bool istotoal=true;
        char w[][11] = {"Yi","Qian","Bai","Shi","Wan","Qian","Bai","Shi",""};
        char n[][11] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
        char str[15];
        cin.getline(str,15);
    
        int length=strlen(str);
         if(length==1 && str[0]=='0'){
            printf("ling");
            return 0;
        }
        if(str[0]=='-'){
            printf("Fu");
            start=1;
        }
        int shulen=length-start;
        for(int i=start;i<length;i++){
            if(str[i]=='0'){
                 if(i==length-5 && istotoal==false)printf(" Wan"); 
    
               while(str[i+1]=='0'&& (i+1)!=length-1 && (i+1)!=length-5){
                   i++;
               }
            if(((i+1)==length-5 && str[i+1]=='0')||((i+1)==length-1 && str[i+1]=='0')||i==length-1||i==length-5){
                
            }else{
                printf(" ling");
            }
                  //if((i+1)==length-5 && istotoal==false){
                 //printf(" Wan"); 
                  //}
            }else{
                if(i==length-1){
                    int curnum=str[i]-'0';
                    if(i>0)printf(" ");
                    printf("%s",n[curnum]);
                }else{
                int curnum=str[i]-'0';
                if(i<length-5 && length-i!=9)istotoal=false;
                if(i>0)printf(" ");
                printf("%s %s",n[curnum],w[8-length+1+i]);
                }
            }
            
        }
        return 0;
    }
    

    当然AC是肯定的


    image.png

    相关文章

      网友评论

          本文标题:PAT 甲级1082 Read Number in Chines

          本文链接:https://www.haomeiwen.com/subject/njysohtx.html