#C1846. Library Inventory Management
Library Inventory Management
Library Inventory Management
You are given an inventory system of a library which maintains a sorted list of unique book titles. The system supports two operations:
- ADD title: Adds a new book title if it does not already exist. After adding, the list should be maintained in sorted order.
- UPDATE old_title,new_title: If old_title exists in the inventory, remove it and add new_title if it is not already in the inventory. The list must remain sorted and have no duplicates.
Implementation Details: You should implement the required operations using a LibraryInventory
class. The constructor initializes the inventory with an already sorted list of unique titles. Use latex format for any formulas if needed. For instance, the sorted property can be represented as \( \text{books} = \{b_1, b_2, \ldots, b_n\} \) such that \( b_1 < b_2 < \ldots < b_n \).
inputFormat
The input is read from standard input and structured as follows:
- An integer
N
representing the number of initial book titles. - The next
N
lines each contain a book title. These titles are guaranteed to be sorted and unique. - An integer
M
representing the number of operations. - The next
M
lines each describe an operation. Each operation is in one of the following formats:ADD title
UPDATE old_title,new_title
(note the comma as delimiter)
Book titles may contain spaces. There will be at least one operation.
outputFormat
Output to standard output the final list of book titles in sorted order, one title per line.
## sample3
Alice in Wonderland
Moby Dick
The Great Gatsby
3
ADD Peter Pan
UPDATE The Great Gatsby,The Catcher in the Rye
UPDATE Moby Dick,Animal Farm
Alice in Wonderland
Animal Farm
Peter Pan
The Catcher in the Rye
</p>