题解 | #牛牛的字符菱形#
学英语
http://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc
C:强行分类,你值得拥有
-
- #include <stdio.h>
-
-
char first[19][10]={{"one"},{"two"},{"three"},{"four"},{"five"},{"six"},{"seven"},{"eight"},{"nine"},{"ten"},{"eleven"},{"twelve"},{"thirteen"},{"fourteen"},{"fifteen"},{"sixteen"},{"seventeen"},{"eighteen"},{"nineteen"}};
-
-
-
char second[9][10]={{"ten"},{"twenty"},{"thirty"},{"forty"},{"fifty"},{"sixty"},{"seventy"},{"eighty"},{"ninety"}};
-
-
-
char third[8]="hundred";
-
-
-
char fourth[9]="thousand";
-
-
-
char fifth[8]="million";
-
-
- void hundred(int n)
-
- {
-
-
if(n>0 && n<1000)
-
-
-
{
-
-
-
if(n>0 && n<20)
-
-
-
printf("%s",first[n-1]);
-
-
-
else if(n>19 && n<100)
-
-
-
{
-
-
-
printf("%s ",second[n/10-1]);
-
-
-
if(n%10!=0)
-
-
-
printf("%s",first[n%10-1]);
-
-
-
}
-
-
-
else
-
-
-
{
-
-
-
printf("%s %s ",first[(n/100)-1],third);
-
-
-
if((n%100)/10>1)
-
-
-
{
-
-
-
printf("and %s ",second[((n%100)/10)-1]);
-
-
-
if(n%10!=0)
-
-
-
printf("%s ",first[n%10-1]);
-
-
-
}
-
-
-
else if((n%100)/10==1)
-
-
-
printf("and %s ",first[n%100-1]);
-
-
-
else if((n%100)/10==0)
-
-
-
{
-
-
-
if(n==100)
-
-
-
printf("%s ",first[n%10-1]);
-
-
-
else
-
-
-
printf("and %s ",first[n%10-1]);
-
-
-
}
-
-
-
-
}
-
-
-
}
-
-
- }
-
- void thousand(int n)
-
- {
-
-
if(n>999 && n<1000000)
-
-
-
{
-
-
-
int i=n/1000;
-
-
-
if(i/100!=0)
-
-
-
{
-
-
-
printf("%s %s ",first[(i/100)-1],third);
-
-
-
if((i%100)/10>1)
-
-
-
{
-
-
-
printf("and %s ",second[((i%100)/10)-1]);
-
-
-
if(i%10!=0)
-
-
-
printf("%s ",first[i%10-1]);
-
-
-
}
-
-
-
else if((i%100)/10==1)
-
-
-
printf("and %s ",first[i%100-1]);
-
-
-
else if((i%100)/10==0)
-
-
-
printf("and %s ",first[i%10-1]);
-
-
-
}
-
-
-
if(i/100==0)
-
-
-
{
-
-
-
if((i%100)/10>1)
-
-
-
{
-
-
-
printf("%s ",second[((i%100)/10)-1]);
-
-
-
if(i%10!=0)
-
-
-
printf("%s ",first[i%10-1]);
-
-
-
}
-
-
-
else if((i%100)/10<=1)
-
-
-
printf("%s ",first[i%100-1]);
-
-
-
}
-
-
-
printf("%s ",fourth);
-
-
-
while(n>1000)
-
-
-
n-=1000;
-
-
-
hundred(n);
-
-
-
}
-
-
- }
-
- void million(int n)
-
- {
-
-
if(n>1000000)
-
-
-
{
-
-
-
int i=n/1000000;
-
-
-
printf("%s %s ",first[i-1],fifth);
-
-
-
while(n>1000000)
-
-
-
n-=1000000;
-
-
-
thousand(n);
-
-
-
}
-
-
- }
-
- int main()
-
- {
-
-
long int n=0;
-
-
-
scanf("%ld",&n);
-
-
-
million(n);
-
-
-
thousand(n);
-
-
-
hundred(n);
-
-
-
return 0;
-
-
- }
- `