#C11990. Categorize Books by Genre

    ID: 41367 Type: Default 1000ms 256MiB

Categorize Books by Genre

Categorize Books by Genre

Given a list of books, each provided in the format Title:Genre, your task is to categorize the books by their genre. For each genre, sort the titles lexicographically (i.e., in dictionary order). Then, output each genre in alphabetical order followed by its sorted book titles. Each genre should be printed on a new line followed by its corresponding titles, each prefixed with two spaces.

If there are no books (i.e., n = 0), print nothing.

The sorting rules can be formally expressed as follows:

( \text{For each genre } g, \text{ let } L(g) \text{ be the sorted list of titles associated with } g. )

( \text{Output the genres in ascending lexicographical order.} )

Please note that the input is read from standard input (stdin) and the output must be written to standard output (stdout).

inputFormat

The first line contains an integer n representing the number of books. Each of the following n lines contains a string in the format Title:Genre.

outputFormat

Print the categorized output. For each genre, first print the genre followed by a colon (:). Then, for each book title in that genre, print a new line with two leading spaces followed by the title. If there are no books, output nothing.

## sample
5
1984:Science Fiction
The Hobbit:Fantasy
The Great Gatsby:Fiction
Foundation:Science Fiction
To Kill a Mockingbird:Fiction
Fantasy:

The Hobbit Fiction: The Great Gatsby To Kill a Mockingbird Science Fiction: 1984 Foundation

</p>