ReWord-wrap
Time limit1sMemory limit1024 MB
Given lines of text and a width w, rewrap the words so no line exceeds w characters without splitting any word.
- Level
Easy3 of 10
- Topics
- String, Greedy, Implementation
- Solved
- No attempts yet
Problem
When the window of a text editor is resized, the words in the text often need to be rearranged so that they fit the screen window without splitting any word. This is called word-wrapping. Given a block of text, word-wrap it to fit a specific size.
Input
The first line contains an integer n, the number of datasets. Each dataset consists of:
- An integer w, the number of characters per line, where .
- An integer m, the number of lines of text to word wrap, where .
- The m lines of text to word wrap.
Output
Output the text word wrapped to the proper number of characters, and print one blank line after each dataset.