关闭

浙大PAT甲级 1082

66人阅读 评论(0) 收藏 举报
分类:

题目需注意0的情况。碰到0不输出,标记=1,碰到数如果标记为1,输出ling,再输出数,标记=0。

AC代码:

#include<iostream>
#include<map>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<list>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#define ll long long
#define inf 999999999
using namespace std;
string ss[5]={"2","3","Shi","Bai","Qian"};
string tmp[10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int main()
{
    string s;
    cin>>s;
    int flag=0;
    if(s[0]=='-')
    {
        printf("Fu");
        flag=1;
        s.erase(0,1);
    }
    int len=s.size();
    if(len<=4)
    {
        int hh=0;
        for(int i=0;i<len;i++)
        {
            if(flag==1)
            {
                if(s[i]=='0')
                {
                    hh=1;
                }
                else
                 {
                     if(hh==1)
                     {
                         cout<<" ling";
                         hh=0;
                     }
                     cout<<" "<<tmp[s[i]-'0'];
                 }

            }
            else
            {
                    cout<<tmp[s[i]-'0'];
                    flag=1;
            }
            if(len-i!=1&&hh!=1)
            {

                cout<<" "<<ss[len-i];
            }
        }
    }
    else if(len>4&&len<=8)
    {
        int hh=0;
        for(int i=0;i<len-4;i++)
        {
            if(flag==1)
            {
                if(s[i]=='0')
                {
                    hh=1;
                }
                else
                 {
                     if(hh==1)
                     {
                         cout<<" ling";
                         hh=0;
                     }
                     cout<<" "<<tmp[s[i]-'0'];
                 }

            }
            else
            {
                cout<<tmp[s[i]-'0'];
                flag=1;
            }
            if(len-4-i!=1&&hh!=1)
            {

                cout<<" "<<ss[len-4-i];
            }
        }
        cout<<" Wan";
        hh=0;
        for(int i=len-4;i<len;i++)
        {
             if(flag==1)
            {
                if(s[i]=='0')
                {
                    hh=1;
                }
                else
                 {
                     if(hh==1)
                     {
                         cout<<" ling";
                         hh=0;
                     }
                     cout<<" "<<tmp[s[i]-'0'];
                 }

            }
            else
            {
                cout<<tmp[s[i]-'0'];
                flag=1;
            }
            if(len-i!=1&&hh!=1)
            {

                cout<<" "<<ss[len-i];
            }
        }
    }
    else
    {
        if(flag==1)
        {
            cout<<" "<<tmp[s[0]-'0'];
        }
        else
        {
            cout<<tmp[s[0]-'0'];
        }
        cout<<" Yi";
        flag=1;
        int hh=0;
        for(int i=len-8;i<len-4;i++)
        {

             if(flag==1)
            {
                if(s[i]=='0')
                {
                    hh=1;
                }
                else
                 {
                     if(hh==1)
                     {
                         cout<<" ling";
                         hh=0;
                     }
                     cout<<" "<<tmp[s[i]-'0'];
                 }

            }
            else
            {
                cout<<tmp[s[i]-'0'];
                flag=1;
            }
            if(len-4-i!=1&&hh!=1)
            {

                cout<<" "<<ss[len-4-i];
            }
        }
        cout<<" Wan";
        hh=0;
        for(int i=len-4;i<len;i++)
        {

             if(flag==1)
            {
                if(s[i]=='0')
                {
                    hh=1;
                }
                else
                 {
                     if(hh==1)
                     {
                         cout<<" ling";
                         hh=0;
                     }
                     cout<<" "<<tmp[s[i]-'0'];
                 }

            }
            else
            {
                cout<<tmp[s[i]-'0'];
                flag=1;
            }
            if(len-i!=1&&hh!=1)
            {

                cout<<" "<<ss[len-i];
            }
        }
    }
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9401次
    • 积分:956
    • 等级:
    • 排名:千里之外
    • 原创:91篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档