#K44442. Organize Movies by Genre
Organize Movies by Genre
Organize Movies by Genre
You are given a series of input lines, each representing a movie along with its genre in the format movie_name : genre
. The input terminates with a line containing only END
. Your task is to group the movies by genre and then output each genre (sorted in lexicographical order) followed by the movies belonging to that genre, where the movies are also sorted in lexicographical order. Each movie under a genre should be printed on a new line with an indentation of two spaces.
For example, if the input is:
The Godfather : Crime
The Dark Knight : Action
Pulp Fiction : Crime
Fight Club : Drama
Forrest Gump : Drama
Inception : Action
END
the output should be:
Action
Inception
The Dark Knight
Crime
Pulp Fiction
The Godfather
Drama
Fight Club
Forrest Gump
Note that the sorting is case-sensitive and follows the usual lexicographical order. You may use the following mathematical notation to denote the order:
$$\text{For any two strings } a \text{ and } b,\ a < b \text{ if } a \text{ comes before } b \text{ in dictionary order.}$$
inputFormat
Input is read from standard input (stdin). Each line represents a movie record in the format movie_name : genre
. The input terminates when a line containing only END
is encountered.
outputFormat
Print the sorted genres and their corresponding movies to standard output (stdout). For each genre, output the genre name on a new line followed by the movie names (each prefixed with two spaces) on subsequent lines. The genres and movies within each genre must be sorted in lexicographical order.## sample
The Godfather : Crime
The Dark Knight : Action
Pulp Fiction : Crime
Fight Club : Drama
Forrest Gump : Drama
Inception : Action
END
Action
Inception
The Dark Knight
Crime
Pulp Fiction
The Godfather
Drama
Fight Club
Forrest Gump
</p>