#C3832. Library Management System

    ID: 47303 Type: Default 1000ms 256MiB

Library Management System

Library Management System

You are given the task of building a library management system. In this system, you need to implement a class (or equivalent) to manage books. The system supports the following operations:

  1. addBook(title, year): Adds a new book with the given title and publication year. Returns True if the book is added successfully. If the book already exists and the stored publication year is the same, still return True. If the book exists but with a different year, return False.

  2. setYear(title, year): Updates the publication year of an existing book. Returns True if updated successfully; if the book does not exist, return False.

  3. getYear(title): Returns the publication year of the book if it exists, otherwise -1.

  4. removeBook(title): Removes the book from the library. Returns True if the removal was successful; if the book does not exist, return False.

  5. getBooks(): Returns a list of book titles in alphabetical order. For output, display the list in the format [Book1, Book2, ...] (without quotes).

All operations above are expected to work correctly in a command processing scenario. In your implementation, you will process a series of operations read from standard input (stdin) and print the result of each operation to standard output (stdout).

Note: Use LaTeX format for any mathematical expressions if needed. For instance, you might denote Boolean values as True\text{True} and False\text{False}.

inputFormat

The input begins with an integer QQ denoting the number of queries. Each query consists of an operation on the library system. The operations are provided as follows:

  • For operations that require additional parameters:
    • For 'addBook' and 'setYear':
      • The next line contains the book title (a string which may contain spaces).
      • The following line contains the publication year (an integer).
    • For 'getYear' and 'removeBook':
      • The next line contains the book title.
  • For 'getBooks': no additional parameters are provided.

Process each query sequentially and output the result of the operation on a separate line. The output formats are:

  • For boolean operations (addBook, setYear, removeBook), output either True or False.
  • For getYear, output the integer year (or -1 if not found).
  • For getBooks, output the list of book titles in the format [Title1, Title2, ...] (if empty, output []).

outputFormat

For each query, output the result of the operation on its own line. Boolean results should be printed as True or False. For getYear, print the corresponding integer. For getBooks, print the list of book titles as described.## sample

10
addBook
1984
1949
addBook
Brave New World
1932
addBook
1984
1949
addBook
1984
1950
setYear
1984
1950
getYear
1984
removeBook
Brave New World
getYear
Brave New World
getBooks
removeBook
Animal Farm
True

True True False True 1950 True -1 [1984] False

</p>