Formatting Text
InterviewTime limit2sMemory limit1024 MB
Read whitespace-separated tokens until END, printing each normal token followed by a space and a newline for each N token.
- Level
Easy2 of 10
- Topics
- String, Implementation, Simulation, Brute force
- Solved
- No attempts yet
Problem
Computers are useful tools for storing, editing, and presenting textual information. When presenting text, one of the most important factors is where to place newlines. In this problem, you should write a program that re-formats text according to a simple set of rules and special markers in the source text.
Input
The input is a sequence of tokens separated by whitespace. Each separator is a single space or newline. All non-whitespace tokens are considered normal except for two special tokens: "N" and "END". The "N" token indicates that a newline should be inserted into the text, and the "END" token indicates the end of input.
Output
Print out each normal token followed by a space. For each occurrence of the special token "N", print a newline.