ECOO '15 R1 P2 - Word Wrap

View as PDF

Submit solution

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 4, 2015, 11:15 p.m.

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


    • 1
      Xyene  commented on April 4, 2015, 11:58 p.m.

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


      • 1
        kobortor  commented on April 5, 2015, 12:10 a.m.

        I know, I just suck at java.


        • 1
          bobhob314  commented on April 5, 2015, 9:05 a.m.

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


          • 3
            BMP  commented on April 8, 2015, 10:05 p.m.

            Hehehe memes.


  • 0
    bobhob314  commented on April 4, 2015, 1:23 p.m. edit 7

    CORRECTIONS TO THE STATEMENT

    There should be a "=====" string after Spiderm\nan at the end of sample output 1.

    There should be 5 "="s, not 4.


    • 2
      Xyene  commented on April 4, 2015, 11:59 p.m.

      Fixed, thanks for noticing.


      • 3
        bobhob314  commented on April 5, 2015, 9:04 a.m.

        There should still be an extra "=====" at the end of the Sample Output. :)

        P.S. I saw Jeffreyxiao and my ovaries exploded.