← 返回 airbnb 的题目列表Print Sentences as Table
类型:online_judge
Given an array of strings sentences (each element is a sentence) and a fixed integer width (e.g., 55), print each sentence as a row in a bordered table:
Each sentence must stay on one single line (no wrapping/splitting).
The content area of each row has fixed size width. If the sentence is shorter than width, pad spaces on the right to reach length width.
Use | as the left and right borders.
Use a horizontal border line above and below each sentence row. The border line starts and ends with + and has - repeated width + 2 times in between (matching the sample).
Output format:
For each sentence: print a border line, then the sentence row, then another border line.
Example
Input:
sentences = ["Hello world", "How are you today", "Bye"]
width = 55
Output (spaces shown conceptually for padding):
+---------------------------------------------------------+
| Hello world |
+---------------------------------------------------------+
| How are you today |
+---------------------------------------------------------+
| Bye |
+---------------------------------------------------------+
Constraints / notes
1 <= width <= 1e4
0 <= len(sentences) <= 1e5
Sentences contain printable ASCII characters and spaces; count width by character length.
Expected time complexity: O(total characters).
Edge cases to clarify
What to do when len(sentence) > width (truncate/error/allow overflow).
How to handle empty sentence ("").
What to output when sentences is empty.
Example
Input
3 55
Hello world
How are you today
Bye
Output
+---------------------------------------------------------+
| Hello world |
+---------------------------------------------------------+
| How are you today |
+---------------------------------------------------------+
| Bye |
+---------------------------------------------------------+