Library Management System: searching for books by author and year

C++ Hard classes

Task «Library Management System: searching for books by author and year»

Implement the Book class, which stores the title, author, and year of publication. Then implement the Library class, which contains a collection of books. The Library class must have methods for adding a book and searching for books by a given author and year of publication (returns a list of book titles sorted by year). If no books are found, return an empty list. In main, the number of books is read, then the data for each book, then the number of queries and the queries themselves (author and year). For each query, output the found book titles or an empty string if nothing is found.

Input Format

First line: integer N (1 ≤ N ≤ 1000) — the number of books. Next N lines, each contains the book title (a string without spaces, up to 100 characters), the author (a string without spaces, up to 100 characters), and the year of publication (an integer from 1000 to 2025), separated by a space. Then a line: integer M (1 ≤ M ≤ 100) — the number of queries. Next M lines, each contains the author (a string without spaces) and the year (an integer), separated by a space.

Output Format

For each query, output on a separate line the titles of books that satisfy the condition, separated by a space, in ascending order of publication year. If there are no books, output an empty line.

Examples

Example 1

INPUT
3 Car Toyota 2020 petrol Bicycle Giant 2019 mountain Car Tesla 2020 electric 2020
OUTPUT
Car: Toyota 2020, fuel: petrol Bicycle: Giant 2019, type: mountain Car: Tesla 2020, fuel: electric 2

Example 2

INPUT
1 Bicycle Merida 2018 road 2018
OUTPUT
Bicycle: Merida 2018, type: road 1
main.cpp