ZOJ Problem Set - 2047
Authors of the new, all-in-one encyclopedia have organized the titles in the order they consider most appropriate for their readers. It's not always alphabetical, because they want to observe some peculiar relationships between them. However, they still want to allow users to look up titles quickly.
They achieve this by adding a carefully calculated number of spaces before every title in the list of titles. They call this structure a dictionary.
A dictionary is represented by a list of words with some number of spaces before certain words. Dictionary format can be described as a set of constraints on sequences of consecutive words starting with the same letter. Any maximal sequence of consecutive words starting with the same letter should satisfy the following rules:
The first word in the group has no spaces before it. Every subsequent word in the group has at least one leading space.
then resulting sequence is a dictionary.
The authors don't feel like giving you a more detailed explanation of what
a dictionary is, so they have included an example (see sample input and output)
that clarifies their definition.
Write to the output the original words in the same order without any trailing spaces but with the appropriate number of leading spaces, so that this word list is a dictionary. There should be no blank lines between the words.
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between
Source: Northeastern Europe 1999