https://vjudge.net/problem/UVA-400
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
int main(){
#ifdef _DEBUG
freopen("in", "rb", stdin);
//freopen("out", "wb", stdout);
#endif // _DEBUG
int N,M;
while (cin >> N) {
printf("------------------------------------------------------------\n");
vector<string> all,ans;
string s;
M = 0;
for (int i = 0; i < N;++i) {
cin >> s;
M = max(M, (int)s.size());
all.push_back(s);
}
sort(all.begin(), all.end());
int n = 62 / (M + 2),cnt=-1;
ans.resize((N - 1) / n + 1);
while (cnt<N) {
for (int i = 0; i < ans.size(); ++i)
if (++cnt < N) {
if (!ans[i].empty()) ans[i] += " ";
ans[i] += all[cnt] + string(M - all[cnt].size(), ' ');
}
}
for (int i = 0; i < ans.size(); ++i)
cout << ans[i] << endl;
}
}