1
//
1715 Accepted 204K 0MS C++ 1314B PKU
2
3 /*
4 1. 首先确定字符串的长度xlen
5 2. 对每一位进行枚举--不断缩小范围
6 */
7 #include < stdio.h >
8 #include < string .h >
9 #include < stdlib.h >
10
11 int inn ;
12 int num ;
13
14 char out [ 10 ] ;
15 int numout[ 10 ] ;
16
17 int A( int n, int m )
18 {
19 int reval = 1 ;
20
21 for ( int i = 0 ; i < m; i ++ ) reval *= (n - i) ;
22
23 return reval ;
24 }
25
26 int main()
27 {
28 while ( scanf( " %d " , & inn ) != EOF )
29 {
30 int xlen = 888 ;
31 for ( xlen = 8 ; xlen >= 1 ; xlen -- )
32 {
33 num = A( 15 , xlen - 1 ) * 15 ;
34 if ( inn > num ) inn = inn - num ;
35 else break ;
36 } // 确定长度为xlen
37
38 // printf( "xlen == %d\n", xlen ) ;
39
40 int first ;
41 for ( first = 15 ; first >= 1 ; first -- )
42 {
43 num = A( 15 , xlen - 1 ) ;
44 if ( inn > num) inn -= num ;
45 else
46 {
47 numout[ 1 ] = first ; break ;
48 }
49 }
50
51 for ( int cxlen = 2 ; cxlen <= xlen; cxlen ++ )
52 {
53 for ( int curposi = 15 ; curposi >= 0 ; curposi -- )
54 {
55 bool contin = false ;
56 for ( int i = 1 ; i < cxlen; i ++ )
57 {
58 if ( curposi == numout[i] ) { contin = true ; break ;}
59 }
60 if ( contin ) continue ;
61
62 num = A( 16 - cxlen, xlen - cxlen ) ;
63 if ( inn > num ) inn -= num ;
64 else
65 {
66 numout[cxlen] = curposi ; break ;
67 }
68 }
69 }
70
71 for ( int i = 1 ; i <= xlen; i ++ )
72 {
73 if ( numout[i] >= 0 && numout[i] <= 9 )
74 printf( " %d " , numout[i] ) ;
75 else
76 printf( " %c " , numout[i] - 10 + ' A ' ) ;
77 }
78 printf( " \n " ) ;
79
80 } // while
81
82 return 0 ;
83 }
2
3 /*
4 1. 首先确定字符串的长度xlen
5 2. 对每一位进行枚举--不断缩小范围
6 */
7 #include < stdio.h >
8 #include < string .h >
9 #include < stdlib.h >
10
11 int inn ;
12 int num ;
13
14 char out [ 10 ] ;
15 int numout[ 10 ] ;
16
17 int A( int n, int m )
18 {
19 int reval = 1 ;
20
21 for ( int i = 0 ; i < m; i ++ ) reval *= (n - i) ;
22
23 return reval ;
24 }
25
26 int main()
27 {
28 while ( scanf( " %d " , & inn ) != EOF )
29 {
30 int xlen = 888 ;
31 for ( xlen = 8 ; xlen >= 1 ; xlen -- )
32 {
33 num = A( 15 , xlen - 1 ) * 15 ;
34 if ( inn > num ) inn = inn - num ;
35 else break ;
36 } // 确定长度为xlen
37
38 // printf( "xlen == %d\n", xlen ) ;
39
40 int first ;
41 for ( first = 15 ; first >= 1 ; first -- )
42 {
43 num = A( 15 , xlen - 1 ) ;
44 if ( inn > num) inn -= num ;
45 else
46 {
47 numout[ 1 ] = first ; break ;
48 }
49 }
50
51 for ( int cxlen = 2 ; cxlen <= xlen; cxlen ++ )
52 {
53 for ( int curposi = 15 ; curposi >= 0 ; curposi -- )
54 {
55 bool contin = false ;
56 for ( int i = 1 ; i < cxlen; i ++ )
57 {
58 if ( curposi == numout[i] ) { contin = true ; break ;}
59 }
60 if ( contin ) continue ;
61
62 num = A( 16 - cxlen, xlen - cxlen ) ;
63 if ( inn > num ) inn -= num ;
64 else
65 {
66 numout[cxlen] = curposi ; break ;
67 }
68 }
69 }
70
71 for ( int i = 1 ; i <= xlen; i ++ )
72 {
73 if ( numout[i] >= 0 && numout[i] <= 9 )
74 printf( " %d " , numout[i] ) ;
75 else
76 printf( " %c " , numout[i] - 10 + ' A ' ) ;
77 }
78 printf( " \n " ) ;
79
80 } // while
81
82 return 0 ;
83 }