#K88897. Book Search
Book Search
Book Search
In this problem, you are given a collection of books and a search query consisting of one or more keywords. Each book is characterized by an integer ID and a set of keywords. Your task is to find all books such that their keywords contain every keyword in the search query. Formally, if a book has keyword set (K) and the query is (Q), then the book is a match if and only if (Q \subseteq K). The output should list the matching book IDs in ascending order.
Note: If the search query is empty, then every book is considered a match.
inputFormat
The input is read from standard input (stdin) and has the following format:
• The first line contains an integer (n) denoting the number of books.
• The next (n) lines each describe one book. Each line starts with an integer ID, followed by an integer (k) representing the number of keywords for that book, and then (k) keywords separated by spaces.
• The next line contains an integer (q) denoting the number of keywords in the query.
• If (q > 0), the next line contains (q) keywords separated by spaces. If (q = 0), the query is empty and every book qualifies.
outputFormat
Print to standard output (stdout) a single line containing the matching book IDs in ascending order, separated by a single space. If no book matches the query, output an empty line.## sample
3
0 2 magic adventure
1 2 science fiction
2 1 adventure
1 adventure
0 2