UVa 400

时间:2022-03-19 23:58:54

一开始没怎么看懂题目,原来就是M字符就是这一列的宽度为M个字符,包括空格。

 #include<iostream>
#include<algorithm>
#include<string>
using namespace std; int main()
{
string filename[];
int n;
while (cin >> n)
{
int cols, rows;
int M = ;
for (int i = ; i < n; i++)
{
cin >> filename[i];
M = max(M, (int)filename[i].length());
}
cols = ( - M) / (M + ) + ;
rows = (n - ) / cols + ;
sort(filename, filename + n);
for (int i = ; i <= ; i++)
cout << "-";
cout << endl;
for (int i = ; i < rows; i++)
{
for (int j = ; j < cols; j++)
{
int t = j * rows + i;
if (t>=n)
continue;
cout << filename[t];
for (int k = ; k <= M - filename[t].length();k++)
{
cout << " ";
}
if (j < cols - )
cout << " ";
}
cout << endl;
}
}
return ;
}