Submission

Status:

PPPPP

Subtask/Task Score:

100/100

Score: 100

User: Dark_kingdom

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

Language: cpp

Time: 0.022 second

Submitted On: 2026-10-08 00:01:28

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct Novel{
	string title;
	int count;
};

bool compareNovels(const Novel& a, const Novel &b)
{
	return a.title <  b.title;
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	
	int height, n;
	if(!(cin>>height>>n)) return 0;
	
	vector<Novel> 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(), compareNovels);
	
	vector<string> final_books;
	for (int i = 0; i<n; i++)
	{
		for (int c = 0 ; c < n_list [i].count; c++)
		{
			final_books.push_back(n_list[i].title);
		}
	}
	
	int t_books = final_books.size();
	
	for (int i = 0; i<t_books; i++)
	{
		cout<<"+-";
	}
	cout<<"+\n";
	
	for (int row = 0; row< height; row++)
	{
		for(int column =0; column<t_books; column++)
		{
			cout<<"|";
			
			int len = final_books[column].length();
			
			if (column%2 == 0)
			{
				if (row<len)
				{
					cout<< final_books[column][row];
				}
				else{
					cout<<".";
				}
			}
			else
			{
				int sp_needed = height - len;
				if (row<sp_needed)
				{
					cout<<".";
				}
				else
				{
					cout<<final_books[column][height -1 - row];
				}
			}
		}
		cout<<"|\n";
	}
	
	for(int i = 0; i<t_books; i++)
	{
		cout<< "+-";
	}
	
	cout<<"+\n";
	
	return 0;
}