#K47137. Library System Operations
Library System Operations
Library System Operations
Implement a library management system that supports three operations: adding a new book, removing a book, and querying a book's details.
The system should maintain a collection of books, where each book is identified by a unique id. When performing an ADD operation, if a book with the same id already exists, update its title and year. For REMOVE and QUERY operations on a non-existent book, the system should output Book not found
.
All operations are provided through standard input. Your program should process each operation sequentially and produce the appropriate output to standard output.
The operations are given in the following formats:
- ADD id title year: Adds a book with the given id, title, and year. The title may contain spaces.
- REMOVE id: Removes the book with the specified id.
- QUERY id: Queries the book with the specified id. If it exists, output its title and year separated by a space.
inputFormat
The input is read from standard input and has the following structure:
- The first line contains a single integer n representing the number of operations.
- Each of the following n lines contains one operation command, which can be one of:
- ADD id title year
- REMOVE id
- QUERY id
Note: The title in an ADD operation may consist of multiple words.
outputFormat
The output is produced on standard output. For each QUERY operation, output the book's title and year separated by a space if the book exists. If a QUERY or REMOVE operation is performed on a non-existent book, output Book not found
. Each output should be on its own line.
5
ADD 1 The Great Gatsby 1925
ADD 2 1984 1949
QUERY 1
REMOVE 1
QUERY 1
The Great Gatsby 1925
Book not found
</p>