hdoj 1727 Hastiness

来源:互联网 发布:手机qq java 编辑:程序博客网 时间:2024/05/19 00:41

Hastiness(链接)

模拟
#include<cstdio>#include<cstring>using namespace std;char one[20][10]={"zero","one","two","three","four","five","six","seven","eight","nine","ten"};char two[20][10]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};char gg[20][10]={"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};int main(){    int num;    while(scanf("%d",&num)!=EOF)    {        int a,b,c,d;        a=num/1000;        b=num%1000/100;        c=num%100/10;        d=num%10;        if(a>0)        {            printf("%s thousand",one[a]);            if(b>0)            {                printf(" and ");                printf("%s hundred",one[b]);                if(c>0)                {                    printf(" and ");                    if(c<2)                    {                        if(d==0)                            printf("%s",one[10]);                        else                            printf("%s",two[d-1]);                    }                    else                    {                        if(d>0)                            printf("%s-%s",gg[c-2],one[d]);                        else                            printf("%s",gg[c-2]);                    }                }                else                {                    if(d>0)                        printf(" and %s",one[d]);                }            }            else            {                if(c>0)                {                    printf(" and ");                    if(c<2)                    {                        if(d==0)                            printf("%s",one[10]);                        else                            printf("%s",two[d-1]);                    }                    else                    {                        if(d>0)                            printf("%s-%s",gg[c-2],one[d]);                        else                            printf("%s",gg[c-2]);                    }                }                else                {                    if(d>0)                        printf(" and %s",one[d]);                }            }        }        else        {            if(b>0)            {                printf("%s hundred",one[b]);                if(c>0)                {                    printf(" and ");                    if(c<2)                    {                        if(d==0)                            printf("%s",one[10]);                        else                            printf("%s",two[d-1]);                    }                    else                    {                        if(d>0)                            printf("%s-%s",gg[c-2],one[d]);                        else                            printf("%s",gg[c-2]);                    }                }                else                {                    if(d>0)                        printf(" and %s",one[d]);                }            }            else            {                if(c>0)                {                    if(c<2)                    {                        if(d==0)                            printf("%s",one[10]);                        else                            printf("%s",two[d-1]);                    }                    else                    {                        if(d>0)                            printf("%s-%s",gg[c-2],one[d]);                        else                            printf("%s",gg[c-2]);                    }                }                else                {                    printf("%s",one[d]);                }            }        }        printf("\n");    }    return 0;}


原创粉丝点击