Posted on 2008-11-02 13:47
Hero 阅读(218)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 // 1656 C++ Accepted 0.015 129 KB URAL
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 const int size = 100 ;
8 int data[size] ;
9 int out[size][size] ;
10
11 int inn ;
12
13 int cmp( const void *a, const void *b )
14 {
15 return *(int *)b - *(int *)a ;
16 }
17
18 void input()
19 {
20 int maxi = inn * inn ;
21 for( int i=1; i<=maxi; i++ ) scanf( "%d", &data[i] ) ;
22
23 qsort( data+1, maxi, sizeof(data[1]), cmp ) ;
24 /*
25 printf( "**************************\n" ) ;
26 for( int i=1; i<=maxi; i++ ) printf( "%d\n", data[i] ) ;
27 printf( "**************************\n" ) ;
28 */
29 }
30
31 void process()
32 {
33 int midrow = ( 1+inn ) / 2 ; int midcol = ( 1+inn ) / 2 ;
34 int pdata = 1 ;//data[]指针
35
36 out[midrow][midcol] = data[pdata++] ;
37 for( int c=midcol-1; c>=1; c-- ) out[midrow][c] = data[pdata++] ;
38 for( int c=midcol+1; c<=inn; c++ ) out[midrow][c] = data[pdata++] ;
39 for( int r=midrow-1; r>=1; r-- ) out[r][midcol] = data[pdata++] ;
40 for( int r=midrow+1; r<=inn; r++ ) out[r][midcol] = data[pdata++] ;
41
42 for( int r=midrow-1; r>=1; r-- )
43 {
44 for( int c=midcol-1; c>=1; c-- ) out[r][c] = data[pdata++] ;
45 for( int c=midcol+1; c<=inn; c++ ) out[r][c] = data[pdata++] ;
46 }
47 for( int r=midrow+1; r<=inn; r++ )
48 {
49 for( int c=midcol-1; c>=1; c-- ) out[r][c] = data[pdata++] ;
50 for( int c=midcol+1; c<=inn; c++ ) out[r][c] = data[pdata++] ;
51 }
52
53 for( int i=1; i<=inn; i++ )
54 {
55 for( int j=1; j<=inn; j++ )
56 {
57 printf( "%d ", out[i][j] ) ;
58 }
59 printf( "\n" ) ;
60 }
61 }
62
63 int main()
64 {
65 while( scanf( "%d", &inn ) != EOF )
66 {
67 input() ;
68
69 process() ;
70
71 //output() ;
72 }
73
74 return 0 ;
75 }