#include
#include
#include
#include
#include
#include
using namespace std;
vectorVstr;
int PrintFormat(int n , int row , int column , int BigestLength)
{
int num = 1;
int remnent , re , amount = 0;
remnent = n % column;
re = remnent;
if(remnent>0) //当矩阵不满足一个完全矩阵时(即每行的每列字符串个数一样)
{
for(int i=1 ; i<=row ; i++){
remnent = re;
num = i;
for(int j = 1; j<=column ; j++){
if(amount==n) //如果输出到最后一行的最后一个时
{
cout<<"\n";
return 0;
}
if( j!=column && remnent!=0) //当处在有多余行数的那几列时
{
cout<<left<<setfill(' ')<<setw(BigestLength+2)<<Vstr[num-1];
amount++;
remnent--;
num = num+row;
}
else if( j==column) //最后一列
{
cout<<left<<setfill(' ')<<setw(BigestLength)<<Vstr[num-1]<<"\n";
amount++;
}
else if(remnent==0) //除了最后一行的前几行的最后几列(除掉与最后一行对齐的几列)
{
cout<<left<<setfill(' ')<<setw(BigestLength+2)<<Vstr[num-1];
num = num+row-1;
amount++;
}
}
}
}else{ //当满足完全矩阵时
for(int i = 1 ; i<=row ; i++){
num = i;
for(int j = 1 ; j<=column ; j++){
if(j!=column)
{
cout<<left<<setfill(' ')<<setw(BigestLength+2)<<Vstr[num-1];
amount++;
num = num + row;
}else{
cout<<left<<setfill(' ')<<setw(BigestLength)<<Vstr[num-1]<<"\n";
amount++;
}
}
}
}
}
int main(){
//freopen("in2.txt","r",stdin);
int n,row,column,BigestLength=0;
int first = 1;
string s;
while(scanf("%d",&n)!=EOF){
BigestLength=0;
Vstr.clear();
for(int i = 0 ; i
cin>>s;
if(s.length()>BigestLength) BigestLength = s.length();
Vstr.push_back(s);
//printf("vector的大小为%d\n",Vstr.size());
}
sort(Vstr.begin() , Vstr.end());
column = (60 - BigestLength) / (BigestLength + 2) + 1, row = (n - 1) / column + 1;
//printf("现在row的值为%d ,column的值为%d ,n的值为%d ,BigestLength的值为%d\n",row,column,n,BigestLength);
printf("------------------------------------------------------------\n");
// printf("现在column为%d row为%d n为%d BigestLength为%d\n",column,row,n,BigestLength);
PrintFormat(n,row,column,BigestLength);
}
return 0;
}