#K62412. Library Management System
Library Management System
Library Management System
You are required to implement a library management system. The system should be able to process a series of commands from stdin and output the results to stdout. The commands include adding books to the library, searching for books by title, author, or year, and generating a report. When a book is added that already exists (i.e. same title and author), the number of copies should be aggregated.
The commands are:
- ADD title author year copies: Adds a new book or increases the copies of an existing book.
- SEARCH BY TITLE title: Searches for all books with the given title.
- SEARCH BY AUTHOR author: Searches for all books written by the given author.
- SEARCH BY YEAR year: Searches for all books published in the given year.
- GENERATE REPORT: Outputs all books sorted in ascending order by their title.
For example, if the command "ADD TheGreatGatsby FScottFitzgerald 1925 3" is followed by "SEARCH BY AUTHOR FScottFitzgerald", the output should be "TheGreatGatsby,FScottFitzgerald,1925,3".
Note: In any search operation, each matching book record should be output as title,author,year,copies on a new line. When generating a report, each record should be printed on a separate line in sorted order by title.
The formula for aggregating copies is given by: \( \text{New Copies} = \text{Existing Copies} + \text{Added Copies} \)
inputFormat
The first line contains an integer n that indicates the number of commands. The following n lines each contain a command as described in the problem statement.
outputFormat
For each search command and the generate report command, output the corresponding book records. Each record should be output on a new line in the format: title,author,year,copies. The output for each test case should exactly match the expected order and format.
## sample2
ADD TheGreatGatsby FScottFitzgerald 1925 3
SEARCH BY AUTHOR FScottFitzgerald
TheGreatGatsby,FScottFitzgerald,1925,3
</p>