#C11477. Digital Library Query System
Digital Library Query System
Digital Library Query System
You are tasked with developing a digital library query system. In this system, each book entry includes the following attributes: title, author, publication_year, genre, and page_count.
The system should accept dynamic queries. Each query contains:
- Filter Conditions: One or more conditions in the format
attribute=value
joined by the stringAND
. A book matches a filter if\(\text{str}(\text{attribute})=\text{value}\)
for every condition. - Sort Attribute: This is provided as the last token in the query line. Books that match the filter must be sorted according to this attribute. Note that string attributes should be sorted lexicographically, while numerical attributes (\(publication\_year\) and \(page\_count\)) should be sorted in numerical order.
If no book meets the filter conditions, output No books found
. Otherwise, output each matching book on a new line with the attributes separated by a single space. For multiple queries, separate the answers with an empty line.
inputFormat
The input is read from standard input. The first line contains an integer p
, the number of books. The next p
lines each contain a book's data: title
, author
, publication_year
, genre
, and page_count
separated by single spaces.
Following this, there is a line with an integer q
, the number of queries. Each of the next q
lines contains one query. A query has the format:
filter_condition1 [AND filter_condition2 ...] sort_attribute
Read from stdin
.
outputFormat
For each query, output the selected books. Each book's attributes should be printed in one line separated by a single space. If multiple books are returned, they must be sorted based on the specified sort attribute. If no book matches, output No books found
.
Write the result to stdout
. For multiple queries, separate the outputs with an empty line.
5
Harry_Potter_1 J.K.Rowling 1997 Fantasy 223
Harry_Potter_2 J.K.Rowling 1998 Fantasy 251
The_Hobbit J.R.R.Tolkien 1937 Fantasy 310
1984 George_Orwell 1949 Dystopian 328
To_Kill_a_Mockingbird Harper_Lee 1960 Fiction 281
1
author=J.K.Rowling AND publication_year=1998 title
Harry_Potter_2 J.K.Rowling 1998 Fantasy 251