SentryOA #3
WW Challenge (Text Justification with Underscores)
估计困难评测数据准备中,可先阅读题面
考点(AI 标注)字符串模拟/实现
Given a string containing a sequence of words separated by whitespace, format it so that each output line is exactly lineLength characters long. Use _ instead of space.
Greedy packing: pack as many words as possible onto each line, separated by at least one underscore.
Even underscore distribution (multi-word lines): distribute extra underscores evenly between words; if they do not divide evenly, the extra underscores are appended to the end of the line.
Single-word lines: center the word — half the padding on the left and the rest on the right; any extra goes to the end.
Hyphenated words: words like "self-inflicted", "pre-approval", "mother-in-law" should be kept on one line if possible. If only the prefix-with-hyphen fits (e.g. "self-"), split the word across lines. Inputs may have whitespace around hyphens ("self - inflicted"); normalize as if there were no whitespace.
Example
"a cat is an animal", 6
→ ["a__cat", "is_an_", "animal"]
"cat is an animal and so is a dog", 12
→ ["cat__is_an_", "animal___and", "so_is_a_dog_"]
"human", 8
→ ["_human__"]
"auto-complete is my go - to", 8
→ ["_auto-__", "complete", "is____my", "_go-to__"]