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;
}