题目:点击打开链接
代码:
#include<stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
int a1[5900];
int main()
{
int i=1;
a1[1]=1;
int a=1,b=1,c=1,d=1;
while(i<=5842)
{
a1[++i]=min4(a1[a]*2,a1[b]*3,a1[c]*5,a1[d]*7);//!!!算法是关键
if(a1[i]==a1[a]*2)
a++;
if(a1[i]==a1[b]*3)
b++;
if(a1[i]==a1[c]*5)
c++;
if(a1[i]==a1[d]*7)
d++;
}
int n;
while(~scanf("%d",&n),n)
{
if(n%10==0||n/10%10==1)
printf("The %dth humble number is %d.\n",n,a1[n]);//这点很无厘头
else if(n%10==1&&n/10%10!=1)
printf("The %dst humble number is %d.\n",n,a1[n]);
else if(n%10==2&&n/10%10!=1)
printf("The %dnd humble number is %d.\n",n,a1[n]);
else if(n%10==3&&n/10%10!=1)
printf("The %drd humble number is %d.\n",n,a1[n]);
else
printf("The %dth humble number is %d.\n",n,a1[n]);
}
return 0;
}