1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #define LEN 60+10
5 char fn[100][LEN];//to make sure the range is safe
6 int cmp(const void* a,const void *b);
7
8 int main()
9 {
10 int n,width=0;
11 int columns,rows;
12 #ifndef ONLINE_JUDGE
13 freopen("in.txt","r",stdin);
14 //freopen("ou.txt","w",stdout);
15 #endif
16 while(scanf("%d",&n)==1)
17 {
18 width=0;
19 for(int i=0; i<n; i++)//input the filenames of n
20 {
21 scanf("%s",fn[i]);int len=strlen(fn[i]);
22 if(width<len)//get the longest filename
23 width=len;
24 }
25 width+=2;//the Requestment
26 int R=60>width?60:width;//
27 columns=R/width;
28 rows=(n+columns-1)/columns;//get the row and it don not need the judgement
29 //qsort
30 qsort(fn,(int)n,sizeof(char)*(LEN),cmp);
31 //put them in the right pos.
32 printf("------------------------------------------------------------\n");
33 for(int i=0;i<rows;i++)
34 {
35 for(int j=i,k=0;k<columns && j<n;j=j+rows,k++)
36 {
37 printf("%s",fn[j]);
38 int len = width-strlen(fn[j]);
39 for( int l=0;l<len;l++) putchar(' ');
40 }
41 printf("\n");
42 }
43 }
44 return 0;
45 }
46 int cmp(const void *a,const void *b){
47 return strcmp((char *)a,(char *)b);
48 }
49
50