#C4727. Library Management System

    ID: 48297 Type: Default 1000ms 256MiB

Library Management System

Library Management System

Implement a Library Management System that keeps track of books and their availability. Your program should support the following commands:

  • ADD <book_title>: Adds a new book with the given title.
  • BORROW <book_title>: Borrows a book if it exists and is available. Otherwise, an error message is printed.
  • RETURN <book_title>: Returns a book if it has been borrowed. Otherwise, an error message is printed.
  • LIST: Lists all books along with their statuses (either available or borrowed).

Note that once a book is borrowed, it cannot be borrowed again until it is returned. This mechanism can be expressed by the formula: $$ \text{status} = \begin{cases} \text{available} & \text{if the book is not loaned out}\\ \text{borrowed} & \text{if the book has been loaned out} \end{cases} $$

inputFormat

The first line contains an integer N representing the number of commands. Each of the following N lines contains one command in one of the following formats:

  1. ADD <book_title>
  2. BORROW <book_title>
  3. RETURN <book_title>
  4. LIST

For commands that include a book title, the title may consist of alphanumeric characters and underscores.

outputFormat

For each command that produces an output (i.e. BORROW, RETURN, and LIST), print the corresponding result on standard output. The output messages must exactly match the specifications below:

  • BORROW: If the book does not exist, output: '<book_title>' does not exist in the library. If the book is already borrowed, output: '<book_title>' is already borrowed. Otherwise, output: You've borrowed '<book_title>'

  • RETURN: If the book does not exist, output: '<book_title>' does not exist in the library. If the book was not borrowed, output: '<book_title>' was not borrowed. Otherwise, output: You've returned '<book_title>'

  • LIST: For each book (in the order they were added), print a line formatted as: <book_title>: ## sample

5
ADD The_Great_Gatsby
ADD War_and_Peace
LIST
BORROW The_Great_Gatsby
LIST
The_Great_Gatsby: available

War_and_Peace: available You've borrowed 'The_Great_Gatsby' The_Great_Gatsby: borrowed War_and_Peace: available

</p>