-
Notifications
You must be signed in to change notification settings - Fork 2
/
UnixLs.cpp
63 lines (53 loc) · 996 Bytes
/
UnixLs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxcol = 60;
// 输出字符串,输出字符串s,长度不足len时补字符extra
void print(string s, int len, char c){
cout<<s;
for(int i = 0; i< len - s.size(); i++){
cout<<c;
}
}
int main()
{
int n;
while(cin>>n){
vector<string> names;
scanf("%d", &n);
int maxlen = 0;
while(n--){
string n;
cin>>n;
names.push_back(n);
maxlen = max(maxlen, (int)n.size());
}
int num = names.size();
// 计算行列
int l = (maxcol - maxlen) / (maxlen+2) + 1, h = 0;
h = num / l;
if(num % l !=0) h++;
print("-", 60, '-');
cout<<endl;
sort(names.begin(), names.end());
for(int i = 0; i< h; i++){
for(int j = 0; j< l; j++){
int z = j * h + i;
if(z < num){
if(j == l-1){
print(names[z], maxlen+2, ' ');
break;
}
else {
print(names[z], maxlen, ' ');
}
}
}
printf("\n");
}
}
return 0;
}