hdoj acm 3.2.5 구 질 수

#include<stdio.h>
int f[5843]; int min(int x,int y) { return x<y?x:y; } int min4(int x,int y,int z,int w) { return min(x,y)>min(z,w)?min(z,w):min(x,y); } int main() { int a,b,c,d,i,n;
	a=b=c=d=1;
	f[1]=1; for(i=2;i<=5842;i++) {
        f[i]=min4(2*f[a],3*f[b],5*f[c],7*f[d]); if(f[i]==2*f[a]) a++; if(f[i]==3*f[b]) b++; if(f[i]==5*f[c]) c++; if(f[i]==7*f[d]) d++; } while(scanf("%d",&n)&&n) { if(n%10==1&&n%100!=11)
			printf("The %dst humble number is %d.
"
,n,f[n]); else if(n%10==2&&n%100!=12) printf("The %dnd humble number is %d.
"
,n,f[n]); else if(n%10==3&&n%100!=13) printf("The %drd humble number is %d.
"
,n,f[n]); else printf("The %dth humble number is %d.
"
,n,f[n]); } return 0; }

좋은 웹페이지 즐겨찾기