UVa 400 Unix Is命令
简单题
#include <bits/stdc++.h>
using namespace std;
const int maxn=110;
string s[maxn];
int main()
{
// freopen("data.in","r",stdin);
ios::sync_with_stdio(false);
int N;
while (cin>>N) {
int maxlen=-1;
for (int i=0;i<N;i++) {
cin>>s[i];
maxlen=max(maxlen,(int)s[i].length());
}
sort(s,s+N);
int col=62/(maxlen+2);
int step=0;
while (step*col<N) {
step++;
}
// cout<<step<<endl;
for (int i=0;i<N;i++) {
int len=s[i].length();
while (len<maxlen) {
s[i]+=' ';
len++;
}
}
for (int i=0;i<60;i++) {
cout<<'-';
}
cout<<endl;
for (int i=0;i<step;i++) {
int len=0;
for (int j=i;j<N;j+=step) {
cout<<s[j];
len+=s[i].length();
if (len+2<=60) {
cout<<" ";
}
}
cout<<endl;
}
}
return 0;
}