Submission
Status:
PPPPP
Score: 100
User: Jibhong
Problemset: ชั้นหนังสือ
Language: cpp
Time: 0.027 second
Submitted On: 2024-12-14 15:59:23
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int L, N;
cin >> L >> N;
vector<string> books;
for (int i = 0; i < N; ++i) {
int Ki;
string Si;
cin >> Ki >> Si;
for (int j = 0; j < Ki; ++j) {
books.push_back(Si);
}
}
// Sort the books alphabetically
sort(books.begin(), books.end());
// Construct the bookshelf
int totalBooks = books.size();
vector<vector<char>> shelf(L, vector<char>(totalBooks, '.'));
for (int col = 0; col < totalBooks; ++col) {
string &title = books[col];
if (col % 2 == 0) { // Upright
for (int row = 0; row < min(L, (int)title.size()); ++row) {
shelf[row][col] = title[row];
}
} else { // Upside-down
for (int row = 0; row < min(L, (int)title.size()); ++row) {
shelf[L - 1 - row][col] = title[row];
}
}
}
// Output the bookshelf
string border = "+";
for (int i = 0; i < totalBooks; ++i) {
border += "-+";
}
cout << border << endl;
for (int row = 0; row < L; ++row) {
cout << "|";
for (int col = 0; col < totalBooks; ++col) {
cout << shelf[row][col] << "|";
}
cout << endl;
}
cout << border << endl;
return 0;
}