FastPrepFastPrep
Problem Brief

Print Sentences as Table

FULLTIMEPHONE SCREEN

Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem.

You are given n sentences and a fixed table content width width. Print each sentence as one row in a bordered table.

Input

The first line contains two integers n and width. The next n lines each contain one sentence. Sentences may contain spaces, and each sentence length is guaranteed to be at most width.

Output

For each sentence, output a border line, then the sentence row, then continue with the next border line. A border line is +, followed by width + 2 dash characters, followed by +.

A sentence row starts with | , then the sentence, then enough trailing spaces to fill exactly width content characters, then |.

If n = 0, return no output lines.

Example

Input: 3 55, followed by Hello world, How are you today, and Bye.

The sample output is shown in the visible example.

Function Description

Complete solvePrintSentencesAsTable. It has one parameter, String input, containing the full stdin payload. Return the stdout payload as an array of lines, without trailing newline characters.

1Example 1

Input
input = "3 55\nHello world\nHow are you today\nBye"
Output
["+---------------------------------------------------------+", "| Hello world |", "+---------------------------------------------------------+", "| How are you today |", "+---------------------------------------------------------+", "| Bye |", "+---------------------------------------------------------+"]
Explanation

The returned string array must match the expected standard output lines for the sample input.

Constraints

Limits and guarantees your solution can rely on.

  • 0 <= n <= 10^5
  • 1 <= width <= 10^4
  • Each sentence contains printable ASCII characters and spaces.
  • Each sentence length is at most width.
public String[] solvePrintSentencesAsTable(String input) {
    // write your code here
}
Input

input

"3 55\nHello world\nHow are you today\nBye"

Output

["+---------------------------------------------------------+", "| Hello world |", "+---------------------------------------------------------+", "| How are you today |", "+---------------------------------------------------------+", "| Bye |", "+---------------------------------------------------------+"]

Sign in to submit your solution.