神犇救救孩子,不开O2优化全RE,开了就30.
查看原帖
神犇救救孩子,不开O2优化全RE,开了就30.
364319
DIgnited楼主2020/9/18 20:49

本地可以啊, 神犇救救我



//P1617 (test2)
#include<bits/stdc++.h>
using namespace std;
int main()
{

    string g[10],t[30],s[12],q[2];
        g[0]="zero";g[1]="one";g[2]="two";g[3]="three";g[4]="four";g[5]="five";
        g[6]="six";g[7]="seven";g[8]="eight";g[9]="nine";g[10]="ten";
//
        t[10]="ten";t[11]="eleven";t[12]="twelve";t[13]="thirteen";t[14]="fourteen";
        t[15]="fifteen";t[16]="sixteen";t[17]="seventeen";
        t[18]="eighteen";t[19]="ninteen";t[20]="twenty";
//
        s[0]="滑稽";s[1]="ten";s[2]="twenty";s[3]="thirty";s[4]="forty";
        s[5]="fifty";s[6]="sixty";s[7]="seventy";s[8]="eighty";s[9]="ninty";
//
        q[0]="hundred";q[1]="thousand";
    char a[6];
    scanf("%s",a);
    int l=strlen(a);
    int num[l+1],shi;memset(num,0,sizeof(num));
    for(int i=0;i<l;i++)
        num[i+1]=a[i]-'0';
    shi=num[l-1]*10+num[l];
    if(num[1]==0&&num[2]==0&&num[3]==0&&num[4]==0)
    {
        cout<<"zero";
        return 0;
    }
    if(num[1]>=1)
        cout<<g[num[1]]<<" "<<q[1]<<" ";
    if(num[2]>=1)
        cout<<g[num[2]]<<" "<<q[0]<<" ";
    else if(num[2]==0&&num[3]>=1||num[4]>=1)
        cout<<"and ";
    if(num[3]>=1&&shi>=10&&shi<=19)
    {
        cout<<t[shi]<<" ";
        return 0;
    }
    else if(num[3]>=1&&shi>=20)
    {
        cout<<s[num[3]]<<" ";
        if(num[4]==0)
            return 0;
        else
        {
            cout<<g[num[4]];
            return 0;
        }
    }
    if(num[3]==0&&num[2]!=0)
        cout<<"and ";
    if(num[4]==0)
        return 0;
    else
    {
        cout<<g[num[4]];
        return 0;
    }
    return 0;
}
2020/9/18 20:49
加载中...