#C7545. Movie Night Friends Selection
Movie Night Friends Selection
Movie Night Friends Selection
In this problem, you are given a list of friends with their favorite movie genres, and a list of available movie genres for a movie night. Your task is to determine which friends can join the movie night based on the availability of their favorite genre.
You will be provided input via standard input (stdin). The input format is as follows:
(\textbf{Input Format}):
- The first line contains an integer (n) representing the number of friends.
- The next (n) lines each contain two strings separated by space: the friend's name and their favorite genre.
- The following line contains an integer (m) representing the number of available genres.
- The next (m) lines each contain one string representing an available genre.
If any part of the input is invalid (for example, non-integer where an integer is expected, or a friend record that does not contain exactly two strings), then you should output an empty line.
(\textbf{Output Format}):
Print the names of friends (in the same order as input) whose favorite genre is included in the list of available genres. The names should be printed on a single line separated by a single space. If no friend qualifies or if the input is invalid, print an empty line.
(\textbf{Validation}): Make sure to validate both the number of friends and available genres as integers and the friend records as exactly two strings. If any validation fails, the output should be empty.
inputFormat
The input is read from stdin and has the following structure:
- An integer n – the number of friends.
- n lines follow, each containing two space-separated strings: a friend's name and their favorite genre.
- An integer m – the number of available genres.
- m lines follow, each containing a genre string.
Note: If the input does not conform to the above format, output an empty line.
outputFormat
Output a single line containing the names of friends whose favorite genre is available, separated by a single space. If no friend qualifies or if the input is invalid, output an empty line.## sample
4
Alice Comedy
Bob Action
Charlie Horror
Daisy Comedy
2
Comedy
Drama
Alice Daisy