#C13200. Library Management System
Library Management System
Library Management System
You are required to implement a library management system that supports various operations on a collection of books. Each book has a title, an author, and a publication year. The operations you must support are:
- ADD: Add a new book. If a book with the same title already exists, output "Book already exists". On successful addition, output "Book added".
- REMOVE: Remove a book by its title. If the book is found and removed, output "Book removed"; if not found, output "Book not found".
- SEARCH: Search for books by a given author. Output each matching book on a separate line in the format:
( \texttt{title by author published in year} )
If no books are found, output "None". 4. LIST_BEFORE: List all books published before a given year (strictly less than the given year), in the order they were added. Use the same format as in SEARCH. If none, output "None". 5. LIST_ALL: List all books in the library in the order they were added, with the same format. If the library is empty, output "None".
The input commands will be provided via standard input (stdin) and all outputs should be sent to standard output (stdout).
All numeric comparisons and operations involving years follow the standard arithmetic rules. In particular, note that the condition for list books before is ( \texttt{book.year} < \texttt{given year} ).
inputFormat
The input begins with an integer ( T ) representing the number of commands. Each of the following ( T ) lines contains a command. The commands can be one of the following five formats:
- ADD title;author;year (Example: ADD Title1;Author1;2000)
- REMOVE title (Example: REMOVE Title1)
- SEARCH author (Example: SEARCH Author1)
- LIST_BEFORE year (Example: LIST_BEFORE 2001)
- LIST_ALL
Note: The title and author fields do not contain the ';' character.
outputFormat
For each command, output the appropriate response as follows:
-
For the ADD command, output "Book added" if the book was successfully added; if a book with the same title already exists, output "Book already exists".
-
For the REMOVE command, output "Book removed" if removal is successful; otherwise, output "Book not found".
-
For the SEARCH, LIST_BEFORE, and LIST_ALL commands, output each matching book on a separate line in the format:
title by author published in year
If there is no matching book (or if the library is empty), output a single line with "None".
Process the commands in the given order.## sample
5
ADD Title1;Author1;2000
ADD Title2;Author2;2001
LIST_ALL
SEARCH Author1
REMOVE Title1
Book added
Book added
Title1 by Author1 published in 2000
Title2 by Author2 published in 2001
Title1 by Author1 published in 2000
Book removed
</p>