#C147. Library System Management
Library System Management
Library System Management
You are required to implement a simple library management system. The library system manages a collection of books and registered members. Each book has a title, an author, and an availability status. Each member is identified by a unique member ID and can borrow books. However, a member may not borrow the same book more than once concurrently and can borrow at most three books at a time.
The system should support the following commands (read from stdin
):
- ADD_BOOK <title> <author>: Add a book with the given title and author. The book is initially available.
- ADD_MEMBER <memberId>: Register a new member with the given member ID.
- BORROW <memberId> <bookTitle>: The member tries to borrow the book with the given title. The following messages should be printed to
stdout
:- If the book is successfully borrowed:
Book borrowed successfully.
- If the member already borrowed the same book:
Cannot borrow the same book multiple times.
- If the member already has three books:
Cannot borrow more than three books.
- If the book is not available or the member/book does not exist:
Book is not available.
- If the book is successfully borrowed:
- RETURN <memberId> <bookTitle>: The member returns the book. Print:
- If the book is returned successfully:
Book returned successfully.
- If the member did not borrow the book:
Cannot return the book.
- If the book is returned successfully:
The input will start with a line containing an integer N representing the number of commands. Each of the following N lines will contain one command. Only the commands BORROW
and RETURN
produce an output line.
Note: All outputs should be printed on a separate line to stdout
.
inputFormat
The first line of input contains an integer N, the number of commands. The following N lines each contain a command in one of the following formats:
ADD_BOOK <title> <author>
ADD_MEMBER <memberId>
BORROW <memberId> <bookTitle>
RETURN <memberId> <bookTitle>
Titles, authors, and member IDs will not contain spaces.
outputFormat
For each BORROW
and RETURN
command, output a single line containing the appropriate message as described in the problem statement.
5
ADD_BOOK 1984 GeorgeOrwell
ADD_MEMBER 001
BORROW 001 1984
RETURN 001 1984
BORROW 001 1984
Book borrowed successfully.
Book returned successfully.
Book borrowed successfully.
</p>