This problem was used in the following GFU competitions:
GFU 2024 D3 Q7
You are in charge of the menus at the Underground Kitchen tonight. You will be given the desired size of the printed menu and everything that needs to be printed on it, and your job is to fit it all as nicely as possible
The first line will contain a single integer n that represents the number of data sets that follow. Each data set will begin with integers denoting the width and height, in characters, of the menu. The next line will contain everything to be printed on the menu of the specified size, every individual word will fit on its own line of the menu with no wrapping.
Output the menu in the format shown below, making certain to left-align all lines as best as possible, with no words running over onto the next line, in other words, all words should be printed entirely on one line. All menus will have a border around the edge, the sides being | chars and the top and bottom being – chars, and all will be completely filled.
Example Input:
2
7 7
Hello its me and you
10 10
Somebody once told me the world was going to roll me
Example Output:
-------
|Hello|
|its |
|me |
|and |
|you |
-------
----------
|Somebody|
|once |
|told me |
|the |
|world |
|was |
|going to|
|roll me |
----------
Note: the text will look more like it is in a box within the terminal
This is a pretty simple program... no real tips/tricks.