#C9419. Library Management System
Library Management System
Library Management System
You are required to build a simple library management system. The system should allow adding books and querying them either by author or by publication year.
Each book has a title, an author, and a publication year. When queried, the results should be returned in lexicographical order (i.e., sorted based on ASCII values).
The system supports three types of queries:
- ADD: Add a new book. The command format is:
ADD title author year
. - AUTHOR: Retrieve all books written by a specific author. The command format is:
AUTHOR author
. - YEAR: Retrieve all books published in a specific year. The command format is:
YEAR year
.
For queries of type AUTHOR
and YEAR
, output the matching book titles in lexicographical order, separated by commas. If no books match the query, output an empty line.
Note: Titles and authors will not contain spaces. Use underscores (_
) to represent spaces if needed.
inputFormat
The first line of input contains an integer Q, which represents the number of queries. The following Q lines each contain a query. Each query can be one of the following:
-
ADD title author year
- title: a string (without spaces, use underscores instead)
- author: a string (without spaces, use underscores instead)
- year: an integer representing the publication year.
-
AUTHOR author
- Retrieves all book titles by the given author.
-
YEAR year
- Retrieves all book titles published in the given year.
All tokens are separated by a single space.
outputFormat
For each query of type AUTHOR or YEAR, output a single line containing the sorted book titles separated by commas. If no books match the query, output an empty line.## sample
6
ADD The_Great_Gatsby F._Scott_Fitzgerald 1925
ADD 1984 George_Orwell 1949
ADD Animal_Farm George_Orwell 1945
AUTHOR George_Orwell
YEAR 1925
AUTHOR Unknown
1984,Animal_Farm
The_Great_Gatsby
</p>