HDU 1058Humble Numbers

作者在 2008-05-13 10:54:26 发布以下内容

http://acm.hdu.edu.cn/showproblem.php?pid=1058

水题  也贴一下

#include<stdio.h>
int humble[5843];
int min(int a, int b, int c, int d)
{
 a=a>b?b:a;
 a=a>c?c:a;
 a=a>d?d:a;
    return a;
}
void main()
{
    int e1=1,e2=1,e3=1,e4=1,a1,a2,a3,a4,i,n;
    humble[1]=1;
    for(i=2;i<=5842;i++)
 {
        a1=2*humble[e1];
        a2=3*humble[e2];
        a3=5*humble[e3];
        a4=7*humble[e4];
        humble[i]=min(a1,a2,a3,a4);
        if(humble[i]==a1)e1++;
        if(humble[i]==a2)e2++;
        if(humble[i]==a3)e3++;
        if(humble[i]==a4)e4++;
    }
    while(scanf("%d",&n)!=EOF&&n)
 {
        printf("The %d",n);
        if(n%10==1 && n%100!= 11)
   printf("st ");
        else if(n%10==2 && n%100!=12)
   printf("nd ");
        else if(n%10==3 && n%100!=13)
   printf("rd ");
        else
   printf("th ");
        printf("humble number is %d.\n",humble[n]);
    }
}

ACM | 阅读 3790 次
文章评论,共1条
艺困充般(游客)
2019-05-08 17:44
1
游客请输入验证码
最新评论