杭电OJ-1058
作者:互联网
#include <stdio.h>
#include <string.h>
int MIN(long long a,long long b)
{
if(a>b) return b;
else return a;
}
int main()
{//先找出满足题意的所有数
int n,pos1,pos2,pos3,pos4;
long long a[5843],min;
//初始化
memset(a,0,sizeof(a));
a[1]=1;pos1=pos2=pos3=pos4=1;
for(int i=2;i<=5842;i++)
{
//保持顺序,依次递增
min=MIN(MIN(a[pos1]*2,a[pos2]*3),MIN(a[pos3]*5,a[pos4]*7));
a[i]=min;
//当前数值已采用,向下延伸一层
if(a[i]==a[pos1]*2) pos1++;
if(a[i]==a[pos2]*3) pos2++;
if(a[i]==a[pos3]*5) pos3++;
if(a[i]==a[pos4]*7) pos4++;
}
while(scanf("%d",&n)!=EOF&&n!=0)
{
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 %lld.\n",a[n]);
}
return 0;
}
JIngles123
发布了34 篇原创文章 · 获赞 5 · 访问量 1万+
私信
关注
标签:OJ,1058,long,杭电,int,pos4,pos2,pos3,pos1 来源: https://blog.csdn.net/qq_40467670/article/details/104520912