ECOO '15 R1 P2 - Word Wrap

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type

Text editors like Notepad usually contain a "word wrap" feature. When it's enabled, long lines will be broken up to fit the screen in such a way that most of the time words don't get chopped up. For example, suppose your viewing window is only 10 characters wide. Then with word wrap turned on, the text below would be formatted as shown.

Original
The quick brown fox jumps over the dog
Word wrapped
The quick
brown fox
jumps over
the dog

Sometimes a text document might contain a word that is longer than the width of the viewing window. In that case, the word will have to be split, but also will be positioned so that it starts in the leftmost position on its line. This is shown below for a window that is 17 characters wide:

Original
One of the longest words in English is antidisestablishmentarianism
Word wrapped
One of the
longest words in
English is
antidisestablishm
entarianism

The input will contain 10 test cases.

The first line of each test case will consist of an integer W, where 1 \le W \le 100. This number represents the width of the viewing window. The next line will contain a list of words, each separated from the next by a single space character. The words consist only of letter characters and there are no punctuation characters.

Your job is to present the list of words according to the word wrapping principles described above. You should print a single line of five = characters immediately after each test case and there must be no blank lines in your output.

Note that the sample input below only contains 5 test cases, but the input files used for judging will contain 10 test cases.

Sample Input

14
Spiderman Spiderman does whatever a spider can
10
Spins a web any size
11
Catches thieves just like flies
7
Look Out
7
Here comes the Spiderman

Sample Output

Spiderman
Spiderman does
whatever a
spider can
=====
Spins a
web any
size
=====
Catches
thieves
just like
flies
=====
Look
Out
=====
Here
comes
the
Spiderm
an
=====

Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org


Comments


  • 1
    kobortor  commented on April 5, 2015, 3:15 a.m.

    mfw I got 95% on this question on ECOO because I was forced to write java (or maybe because of my own incompetence)


    • 2
      Xyene  commented on April 5, 2015, 3:58 a.m.

      It's fully possible to do it in Java though.


      • 0
        kobortor  commented on April 5, 2015, 4:10 a.m.

        I know, I just suck at java.


        • 0
          bobhob314  commented on April 5, 2015, 1:05 p.m.

          Next time you should stay in the B-team :(