cswork / OAOpen practice workspace

AirbnbOA #6

Print Sentences as Table

EasyJudge-ready

Topics (AI-labelled)Strings

Given n sentences and a fixed table content width width, print each sentence as one row of a bordered table.

A border line is +, followed by width+2 copies of -, followed by +. A sentence line is | , followed by the sentence itself, padded with spaces so the content takes exactly width characters, followed by |.

For each sentence in order, output a border line and then its sentence line; finish with one more border line. When n=0, output nothing.

Input

The first line contains two integers n and width. Each of the next n lines contains one sentence (the whole line is the sentence content; it may contain spaces and may be an empty line).

0≤n≤100000, 1≤width≤300; sentences consist of printable ASCII characters and spaces, with length at most width.

Output

When n>0, output a table of 2n+1 lines, each ending with a newline; when n=0, the output is empty. The output is compared character by character, so leading and trailing spaces of sentences must be preserved exactly.

Example 1

Input:

3 55
Hello world
How are you today
Bye

Output:

+---------------------------------------------------------+
| Hello world                                             |
+---------------------------------------------------------+
| How are you today                                       |
+---------------------------------------------------------+
| Bye                                                     |
+---------------------------------------------------------+

Example 2

Input:

0 5

Output:

Example 3

Input:

4 6
  ab

x y z 
|-+|-+

Output:

+--------+
|   ab   |
+--------+
|        |
+--------+
| x y z  |
+--------+
| |-+|-+ |
+--------+

Example notes

Example 1: width=55, so every border is + followed by 57 copies of - and then +; each sentence line pads the sentence with spaces to 55 characters. Example 2: n=0, so there is no output. Example 3: the two leading spaces of the first sentence, the empty second sentence, and the trailing space of the third sentence all count toward the content width as is.

Editorial

Loading solution…