#C6440. Library Book Borrowing System
Library Book Borrowing System
Library Book Borrowing System
You are required to implement a simple library book borrowing system. The system supports three operations:
- borrow X: Borrow a book with ID \(X\). If the book is not already borrowed, mark it as borrowed and print a success message; otherwise, print that the book is already borrowed.
- return X: Return a book with ID \(X\). If the book has been borrowed, mark it as returned and print a success message; otherwise, print that the book was not borrowed.
- list: List all currently borrowed book IDs in ascending order, separated by spaces. If no books are borrowed, print an empty line.
Your program should read input from standard input and produce output to standard output.
inputFormat
The first line contains an integer (N), representing the number of commands. Each of the following (N) lines contains a command. A command can be one of the following:
borrow X
where \(X\) is an integer book id.return X
where \(X\) is an integer book id.list
to print all currently borrowed books in ascending order.
outputFormat
For each command, output the corresponding response on a separate line. For the borrow
and return
commands, output the appropriate message:
- "Book borrowed successfully" or "Book already borrowed" for
borrow
. - "Book returned successfully" or "Book was not borrowed" for
return
.
list
command, print all borrowed book ids in ascending order separated by a single space. If no book is borrowed, output an empty line.## sample
6
borrow 1
borrow 1
return 1
return 1
borrow 2
list
Book borrowed successfully
Book already borrowed
Book returned successfully
Book was not borrowed
Book borrowed successfully
2
</p>