Posted on 2008-09-27 18:08
Hero 阅读(224)
评论(1) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 // 2247 Accepted 256K 735MS C++ 2016B PKU
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 int inn ;
8
9 typedef unsigned int unint ;
10 typedef unsigned long long llong ;
11
12 const int size = 1000000 ;
13 const llong INF = 21e8 ;
14
15 llong que[size] ;
16 int head, tail ;
17
18 int p2, p3, p5, p7 ;
19
20 int main()
21 {
22 while( scanf( "%d", &inn ) != EOF && inn )
23 {
24 head = tail = 1 ; que[tail++] = 1 ;
25 p2 = p3 = p5 = p7 = 1 ;
26
27 int p ; int num ; int tnum ;
28 for( int i=2; i<=inn; i++ )
29 {
30 num = INF ;
31 if( p2 < tail )
32 {
33 tnum = que[p2] * 2 ;
34 if( num > tnum ) { num = tnum ; p = p2 ; }
35 }
36 if( p3 < tail )
37 {
38 tnum = que[p3] * 3 ;
39 if( num > tnum ) { num = tnum ; p = p3 ; }
40 }
41 if( p5 < tail )
42 {
43 tnum = que[p5] * 5 ;
44 if( num > tnum ) { num = tnum ; p = p5 ; }
45 }
46 if( p7 < tail )
47 {
48 tnum = que[p7] * 7 ;
49 if( num > tnum ) { num = tnum ; p = p7 ; }
50 }
51
52 //printf( "p2==%d p3==%d p5==%d p7==%d p==%d num==%d\n",p2,p3,p5,p7,p, num ) ;
53
54
55 if( num == que[tail-1] )
56 {
57 i-- ;
58 }
59 else
60 {
61 que[tail++] = num ;
62 }
63 if( p2 == p ) p2++ ;
64 else if( p3 == p ) p3++ ;
65 else if( p5 == p ) p5++ ;
66 else if( p7 == p ) p7++ ;
67 }
68
69
70 int tinn = inn % 100 ;
71 if( 11 == tinn )
72 {
73 printf( "The %dth humble number is %lld.\n", inn, que[inn] ) ;
74 }
75 else if( 12 == tinn )
76 {
77 printf( "The %dth humble number is %lld.\n", inn, que[inn] ) ;
78 }
79 else if( 13 == tinn )
80 {
81 printf( "The %dth humble number is %lld.\n", inn, que[inn] ) ;
82 }
83
84 else
85 {
86
87 tinn = inn % 10 ;
88
89 if( 1 == tinn )
90 {
91 printf( "The %dst humble number is %lld.\n", inn, que[inn] ) ;
92 }
93 else if( 2 == tinn )
94 {
95 printf( "The %dnd humble number is %lld.\n", inn, que[inn] ) ;
96 }
97 else if( 3 == tinn )
98 {
99 printf( "The %drd humble number is %lld.\n", inn, que[inn] ) ;
100 }
101 else
102 {
103 printf( "The %dth humble number is %lld.\n", inn, que[inn] ) ;
104 }
105 }
106 }
107
108 return 0 ;
109 }