Submission

Status:

PPPPP

Subtask/Task Score:

100/100

Score: 100

User: anonymous

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

Language: cpp

Time: 0.022 second

Submitted On: 2026-10-27 11:04:49

#include <bits/stdc++.h>
using namespace std;

struct book{
	string title;
	int count;
};

bool cmp(const book& a, const book &b)
{
	return a.title <  b.title;
}

int main()
{
	ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

	int h, n; cin >> h >> n;

	vector<book> n_list(n);
	for (int i = 0; i<n; i++) cin>> n_list[i].count >>n_list[i].title;

	sort(n_list.begin(), n_list.end(), cmp);
	vector<string> f;

	for (int i = 0; i<n; i++)
	{
		for (int c = 0 ; c < n_list[i].count; c++)
		{
			f.push_back(n_list[i].title);
		}
	}

	int t_books = f.size();
	for (int i=0;i<t_books;i++)cout<<"+-";
	cout<<"+\n";

	for (int r=0;r<h;r++)
	{
		for(int c =0; c<t_books; c++)
		{
			cout<<"|";
			if (c%2 == 0)
			{
				if (r < f[c].length()) cout<< f[c][r];
				else cout<<".";
			}
			else
			{
				int a = h - f[c].length();
				if (r<a) cout<<".";
				else cout<<f[c][h-1-r];
			}
		}
		cout<<"|\n";
	}
	for(int i = 0; i<t_books; i++)cout<< "+-";
	cout<<"+";
}