1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include
23 #include
24 using namespace std;
25 const int N=5843;
26 int num;
27 double Prim[4]={2,3,5,7};
28 int id[4]={1,1,1,1};
29 int h[N];
30 char s[4][3]={"th","st","nd","rd"};
31 int Humble()
32 {
33 double Max=INT_MAX;
34 double tmp;
35 int k;
36 for(int i=0;i<4;i++)
37 {
38 tmp=Prim[i]*h[id[i]];
39 if(tmp<Max)
40 {
41 Max=tmp;
42 k=i;
43 }
44 }
45 id[k]++;
46 return int(Max);
47 }
48 void Init()
49 {
50 h[1]=1;
51 num=1;
52 for(num=2;num<N;num++)
53 {
54 h[num]=Humble();
55 if(h[num]==h[num-1])
56 num--;
57 }
58 }
59 void OutPut(int n)
60 {
61 int k=0;
62 if(n%10==1&&n%100!=11)
63 k=1;
64 else if(n%10==2&&n%100!=12)
65 k=2;
66 else if(n%10==3&&n%100!=13)
67 k=3;
68 printf("The %d%s humble number is %d.\n",n,s[k],h[n]);
69 }
70 int main()
71 {
72 int n;
73 Init();
74 while(scanf("%d",&n),n)
75 {
76 OutPut(n);
77 }
78 }
hdu1058 参考答案 (2008-11-12 14:21:19由218编辑)