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[],k,num;
int leap,leap1,leap2,leap3,leap4,leap5,leap6,leap7,leap8,leap9,leap10;
char str[][]=
{
"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[],"thirty");
strcpy(str[],"forty");
strcpy(str[],"fifty");
strcpy(str[],"sixty");
strcpy(str[],"seventy");
strcpy(str[],"eighty");
strcpy(str[],"ninety");
scanf("%d",&T);
while(T--)
{
memset(a,,sizeof(a));
leap=leap1=leap2=leap3=leap4=leap5=leap6=leap7=leap8=leap9=leap10=;
scanf("%d",&num);
i=;
k=num;
if(num>&&num%>=) leap=;
while(k!=)
{
a[i++]=k%;
k=k/;
}
k=i-;
if(k==||k==) {printf("%s\n",str[num]);continue;}
if(k==) {if(num>&&num<=||num%==) printf("%s\n",str[num]);
else printf("%s-%s\n",str[num-num%],str[num%]);continue;}
go();
printf("\n"); }
return ;
}
void go(void)
{
int temp1,temp2,temp3; if(a[]) {printf("%s billion",str[a[]]);leap10=;}
if((leap&&k>=)||(leap10&&a[]!=)||(leap10&&a[]!=)||(leap10&&a[]!=)||(leap10&&a[]!=)||(leap10&&a[]!=)||(leap10&&a[]!=))
printf(", "); if(a[]) {printf("%s hundred",str[a[]]);leap9=;}
temp1=a[]*+a[];
if(leap9&&temp1!=) printf(" and ");
if(temp1!=)
{
if((temp1>&&temp1<=)||temp1%==) printf("%s",str[temp1]);
else printf("%s-%s",str[temp1-temp1%],str[temp1%]);
leap7=;
}
if(leap9||leap7) printf(" million");
if((leap&&k>=)||((leap9&&a[]!=)||(leap7&&a[]!=))||((leap9&&a[]!=)||(leap7&&a[]!=))||((leap9&&a[]!=)||(leap7&&a[]!=))) printf(", "); if(a[]) {printf("%s hundred",str[a[]]);leap6=;}
temp2=a[]*+a[];
if(leap6&&temp2!=) printf(" and ");
if(temp2!=)
{
if((temp2>&&temp2<=)||temp2%==) printf("%s",str[temp2]);
else printf("%s-%s",str[temp2-temp2%],str[temp2%]);
leap4=;
}
if(leap6||leap4) printf(" thousand");
if(leap) printf(", ");
if(a[]) {printf("%s hundred",str[a[]]);leap3=;}
temp3=a[]*+a[];
if((leap3&&temp3!=)||(a[]==&&temp3!=)) printf(" and ");
if(temp3!=)
{
if((temp3>&&temp3<=)||temp3%==) printf("%s",str[temp3]);
else printf("%s-%s",str[temp3-temp3%],str[temp3%]);
}
}