Susquehanna International GroupOA #6
Newspaper Page LEFT/RIGHT Justification
估计中等评测数据准备中,可先阅读题面
考点(AI 标注)字符串模拟/实现
You are moderating a newspaper page. Inputs:
paragraphs: array of paragraphs, where each paragraph is an array of words.aligns: array of per-paragraph alignment flags, each either"LEFT"or"RIGHT".width: max characters allowed on one output line.
Produce the page as follows:
- For each paragraph, greedily pack as many words as fit into a line of length ≤
width, separated by single spaces; overflow words go to the next line. - Pad each line to exactly
widthcharacters: whenaligns[i] == "LEFT", extra spaces go to the end (trailing); whenaligns[i] == "RIGHT", extra spaces go to the beginning (leading). - Surround the entire output with a
*border: a top and bottom row ofwidth + 2asterisks, and a single*at the start and end of every content line.
Example: paragraphs = [["hello", "world"], ["How", "areYou", "doing"], ["Please look", "and align", "to right"]], aligns = ["LEFT", "RIGHT", "RIGHT"], width = 16.
[
"******************",
"*hello world *",
"*How areYou doing*",
"* Please look*",
"* and align*",
"* to right*",
"******************"
]
Constraints
- 1 ≤
paragraphs.length≤ 50 aligns.length == paragraphs.length- 5 ≤
width≤ 100