#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
#define LOCAL
int cmp_string(const void *_a,const void *_b)
{
char *a=(char *)_a;
char *b=(char *)_b;
return strcmp(a,b);
}
int main()
{
#ifdef LOCAL
freopen("400in.txt","r",stdin);
freopen("400o.txt","w",stdout);
#endif
int N,row,maxlen,eachline,flag,rightlen,total;
double tag=0;
char name[120][80];
while(scanf("%d",&N)!=EOF)
{
maxlen=0;row=0;eachline=0;flag=1;total=0;
getchar();
for(int i=0;i<N;i++)gets(name[i]);
qsort(name,N,sizeof(name[0]),cmp_string);
for(int i=0;i<N;i++)
{
if(strlen(name[i])>maxlen)maxlen=strlen(name[i]);
}
rightlen=maxlen;
maxlen=maxlen+2;
if(maxlen<=60)
{
eachline=60/maxlen;
if(60%maxlen!=0)
{
total=maxlen*eachline+rightlen;
if(60/total>=1)eachline++;
}
tag=(double)N/eachline;
row=N/eachline;
if(tag-row>0)row++;
}
else {eachline=1,row=N;}
for(int i=0;i<60;i++)printf("-");
printf("\n");
for(int i=0;i<row;i++)
{
for(int j=0;j<eachline;j++)
{
if(i+j*row>=N)break;
printf("%s",name[i+j*row]);
if(j<eachline)
{
for(int k=0;k<maxlen-strlen(name[i+j*row]);k++)printf(" ");
}
else
{
for(int k=0;k<rightlen-strlen(name[i+j*row]);k++)printf(" ");
}
}
printf("\n");
}
}
return 0;
}
UVA - 400 - Unix ls
最新推荐文章于 2021-01-31 16:13:08 发布