Submission

Status:

PPPPP

Subtask/Task Score:

100/100

Score: 100

User: ChanakanStudy

Problemset: ชั้นหนังสือ

Language: cpp

Time: 0.029 second

Submitted On: 2026-10-15 11:52:45

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <numeric>
#include <iomanip>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    vector<pair<string , int>> allbook;
    int l , n;
    cin >> l >> n;
    while(n--) {
        string name;
        int temp;
        cin >> temp >> name;
        allbook.push_back({name , temp});
    }
    sort(allbook.begin() , allbook.end());

    vector<string> collectbook;
    int count = 0,sum = 0;
    for(auto it : allbook) {
        for(int i = 0 ;i < it.second ;i++) {
            string ans = "";
            if(count%2==0) {
                ans += it.first;
                while(ans.size() != l) {
                    ans += ".";
                }
            }
            else {
                int temp = l - it.first.size();
                while(temp--) {
                    ans += ".";
                }
                string temu = it.first;
                reverse(temu.begin() , temu.end());
                for(auto it : temu) {
                    ans += it;
                }
            }
            collectbook.push_back(ans);
            count++;
        }
        sum += it.second;
    }
    // sum += 1;
    // for(auto it : collectbook) {
    //     cout << it << '\n';
    // }

    for(int i = 0 ; i<sum*2+1;i++) {
        if(i % 2 == 0) {
            cout << "+";
        }
        else {
            cout << "-";
        }
    }
    cout << '\n';
    char table[l][sum*2+1];
    for(int i = 0;i<l;i++) {
        for(int j = 0 ; j<sum*2+1;j++) {
            if(j % 2 == 0) {
                table[i][j] = '|';
            }
            else {
                table[i][j] = 'A';
            }
        }
    }

    count = 0;
    for(auto it : collectbook) {
        int l = 0;
        for(auto c : it) {
            table[l][2*count+1] = c;
            l++;
        }
        count++;    
    }

    for(int i = 0;i<l;i++) {
        for(int j = 0 ; j<sum*2+1;j++) {
            cout << table[i][j];
        }
        cout << '\n';
    }

    for(int i = 0 ; i<sum*2+1;i++) {
        if(i % 2 == 0) {
            cout << "+";
        }
        else {
            cout << "-";
        }
    }
    return 0;
}