-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP400.cpp
41 lines (38 loc) · 1008 Bytes
/
P400.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
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
typedef std::vector<std::string> Vector;
void printSpaces(int n) {
for(int i = 0; i < n; ++i)
printf(" ");
}
int main() {
int N;
std::string s;
while(std::cin >> N) {
printf("------------------------------------------------------------\n");
Vector v;
unsigned int maxLength = 1;
for(int i = 0; i < N; ++i) {
std::cin >> s;
if(s.size() > maxLength)
maxLength = s.size();
v.push_back(s);
}
std::sort(v.begin(), v.end());
int columns = (60-maxLength)/(maxLength+2)+1; // (C - 1) * (L + 2) + L <= 60
int rows = (N+columns-1)/columns;
for(int row = 0; row < rows; ++row) {
for(int column = 0; column < columns; ++column) {
int idx = rows*column+row;
if(idx >= N)
break;
if(column > 0)
printSpaces(2+maxLength-v[rows*(column-1)+row].size());
printf("%s", v[idx].c_str());
} // for columns
printf("\n");
} // for rows
} // while N
}