#K58832. Search Books
Search Books
Search Books
You are given a library of books and a set of search criteria. Each book has a title, author, genre, and a year of publication. Your task is to search for books that match all the given criteria.
The search should be case-insensitive for string attributes. For example, when the criteria specifies the title as the great gatsby
, it should match a book with the title The Great Gatsby
. For numeric fields such as the year, the comparison should be exact.
Formally, let library
be a list of books where each book is a dictionary with keys \(title\), \(author\), \(genre\), and \(year\). Let criteria
be a dictionary with some of these keys. A book matches the criteria if for every key \(k\) in criteria
, the following holds:
\[
\text{if } k \text{ is a string field: } \text{lower}(book[k]) = \text{lower}(criteria[k]), \quad \text{if } k \text{ is a numeric field: } book[k] = criteria[k].
\]
If no book matches the criteria, output "No match found".
inputFormat
The input is given in the following format:
- An integer n denoting the number of books in the library.
- n lines follow, each line containing the details of a book in the format:
title,author,genre,year
Note thatyear
is an integer. - An integer k representing the number of search criteria.
- k lines follow, each line containing a key and a value separated by space. The key will be one of
title
,author
,genre
, oryear
. For theyear
key, the value will be an integer.
You should read input from stdin
.
outputFormat
Output the titles of the books that match the given search criteria, in the same order as they appear in the library. Each title should be printed on a new line.
If no books match, print No match found
.
The output should be written to stdout
.
4
To Kill a Mockingbird,Harper Lee,Fiction,1960
1984,George Orwell,Dystopian,1949
Moby Dick,Herman Melville,Adventure,1851
The Great Gatsby,F. Scott Fitzgerald,Fiction,1925
1
author George Orwell
1984
</p>