Submission
Status:
-P--x
Score: 20
User: Winzzwz
Problemset: ชั้นหนังสือ
Language: cpp
Time: 0.004 second
Submitted On: 2024-11-10 18:18:23
#include <bits/stdc++.h>
using namespace std;
vector<string> books;
int l,n;
bool cmp(string a, string b) {
int mn = min(a.size(), b.size());
for (int i = 0; i < mn; i++) {
if (a[i] < b[i]) return true;
else if (a[i] > b[i]) return false;
}
return true;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> l >> n;
for (int i = 0; i < n; i++) {
int k;
string s;
cin >> k >> s;
for (int j = 0; j < k; j++) {
books.push_back(s);
}
}
int sz = books.size();
sort(books.begin(),books.end(),cmp);
for (int i = 1; i <= 2*sz+1; i++) {
if (i%2 == 1) cout << '+';
else cout << '-';
}
cout << "\n";
for (int i = 0; i < l; i++) {
for (int j = 1; j <= sz; j++) {
int v = (j%2 == 1) ? i : sz-i+1;
int nj = j-1;
if (j == 1) cout << '|';
if (v >= 0 && v < books[nj].size()) cout << books[nj][v];
else cout << '.';
cout << '|';
}
cout << '\n';
}
for (int i = 1; i <= 2*sz+1; i++) {
if (i%2 == 1) cout << '+';
else cout << '-';
}
}
/*
15 4
1 AMOGUS
4 ILOVEPEEM
3 ILOVELUKNUT
5 VIEWEWEWEW
*/