码迷,mamicode.com
首页 > 其他好文 > 详细

F Takio与Blue的人生赢家之战

时间:2015-01-31 10:34:36      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit:1000MS  Memory Limit:65535K

题型: 编程题   语言: 无限制

 

描述

在那个风起云涌的SCAU ACM里,有两位人生赢家,他们分别是大洲Takio神和Blue神。      (尤其是blue神。)
由于这两位人生赢家代码能力强,才高八斗,学富五车,英俊潇洒,玉树临风,独步江湖,呼风唤雨,妹子纷至沓来。
而小邪由于太渣了,只能默默地帮他们记录下他们换了多少个妹子。
以上背景纯属题目需要,其实两位大神是很专情的。
终于有一天,小邪计算出他们身边妹子的总数n,想要给Takio神和Blue神。
但是Takio神和Blue神的邮箱是使用英文的,而小邪的英语又很渣,于是无法将n翻译成英语发过去。
但是,小邪想到了你——聪明的14级新生,向你寻求答案。

出题人:K·小邪

 

 

输入格式

第一行是一个整数t(t <= 100),代表样例个数
对于每个样例有一个整数n(0<=n<=2000000000)

 

输出格式

对于每个n,输出其英文表现形式,具体格式见样例输出

 

输入样例

4
5
121
1010
1008611

 

输出样例

five
one hundred and twenty-one
one thousand and ten
one million, eight thousand, six hundred and eleven

 

Hint


输出不一定符合英语规范,但是要符合Sample的规范
对于一个n>1000,若n%1000 >= 100(%代表取余操作)且不为0,且在n%1000对应的英文输出前(如果存在)用","相连而不是"and"




需要用到的英文单词为(不包括引号):
"zero","one","two","three","four","five","six","seven","eight","nine"
"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"
"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"
"hundred","thousand","million","billion"
分别代表
0,1,2,3,4,5,6,7,8,9
10,11,12,13,14,15,16,17,18,19
20,30,40,50,60,70,80,90
100,1000,1000000,1000000000
技术分享
#include<stdio.h>
#include<string.h>
void go(void);
int a[12],k,num;
int leap,leap1,leap2,leap3,leap4,leap5,leap6,leap7,leap8,leap9,leap10;
char str[100][100]=
{
    "zero","one","two","three","four","five","six",
    "seven","eight","nine","ten","eleven","twelve",
    "thirteen","fourteen","fifteen","sixteen",
    "seventeen","eighteen","nineteen","twenty"
};


int main()
{
    int i,k,T;


    strcpy(str[30],"thirty");
    strcpy(str[40],"forty");
    strcpy(str[50],"fifty");
    strcpy(str[60],"sixty");
    strcpy(str[70],"seventy");
    strcpy(str[80],"eighty");
    strcpy(str[90],"ninety");
    scanf("%d",&T);
    while(T--)
    {
        memset(a,0,sizeof(a));
        leap=leap1=leap2=leap3=leap4=leap5=leap6=leap7=leap8=leap9=leap10=0;
        scanf("%d",&num);
        i=1;
        k=num;
        if(num>1000&&num%1000>=100) leap=1;
        while(k!=0)
        {
            a[i++]=k%10;
            k=k/10;
        }
        k=i-1;
        if(k==0||k==1) {printf("%s\n",str[num]);continue;}
        if(k==2) {if(num>0&&num<=20||num%10==0) printf("%s\n",str[num]);
        else printf("%s-%s\n",str[num-num%10],str[num%10]);continue;}
      go();
      printf("\n");

    }
    return 0;
}
void go(void)
{
    int temp1,temp2,temp3;

    if(a[10]) {printf("%s billion",str[a[10]]);leap10=1;}
    if((leap&&k>=9)||(leap10&&a[9]!=0)||(leap10&&a[8]!=0)||(leap10&&a[7]!=0)||(leap10&&a[6]!=0)||(leap10&&a[5]!=0)||(leap10&&a[4]!=0))
    printf(", ");


    if(a[9]) {printf("%s hundred",str[a[9]]);leap9=1;}
    temp1=a[8]*10+a[7];
    if(leap9&&temp1!=0) printf(" and ");
    if(temp1!=0)
    {
        if((temp1>0&&temp1<=20)||temp1%10==0) printf("%s",str[temp1]);
        else printf("%s-%s",str[temp1-temp1%10],str[temp1%10]);
        leap7=1;
    }
    if(leap9||leap7) printf(" million");
    if((leap&&k>=7)||((leap9&&a[6]!=0)||(leap7&&a[6]!=0))||((leap9&&a[5]!=0)||(leap7&&a[5]!=0))||((leap9&&a[4]!=0)||(leap7&&a[4]!=0))) printf(", ");



    if(a[6]) {printf("%s hundred",str[a[6]]);leap6=1;}
    temp2=a[5]*10+a[4];
    if(leap6&&temp2!=0) printf(" and ");
    if(temp2!=0)
    {
        if((temp2>0&&temp2<=20)||temp2%10==0) printf("%s",str[temp2]);
        else printf("%s-%s",str[temp2-temp2%10],str[temp2%10]);
        leap4=1;
    }
    if(leap6||leap4) printf(" thousand");
    if(leap) printf(", ");
    if(a[3]) {printf("%s hundred",str[a[3]]);leap3=1;}
    temp3=a[2]*10+a[1];
    if((leap3&&temp3!=0)||(a[3]==0&&temp3!=0)) printf(" and ");
    if(temp3!=0)
    {
        if((temp3>0&&temp3<=20)||temp3%10==0) printf("%s",str[temp3]);
        else printf("%s-%s",str[temp3-temp3%10],str[temp3%10]);
    }
}
View Code

 

F Takio与Blue的人生赢家之战

标签:

原文地址:http://www.cnblogs.com/orchidzjl/p/4263639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!