#C3804. Library Management System
Library Management System
Library Management System
You are given a library system where each book is represented by its title and the number of available copies.
You need to implement a system that processes various operations on the library. The operations are:
- borrow <title>: Decrease the book count by one if it is available (i.e. number of copies > 0) and output
Borrowed successfully
. If the book is not available (including if the title does not exist in the library), outputBook not available
. - return <title>: Increase the book count by one. If the book does not already exist in the library, add it with count 1. Always output
Returned successfully
. - report: Output a report of all books in the library, sorted in lexicographic order by the book title. The report should be printed in one line with each book represented as title:count and each pair separated by a space.
Internally, if you let \( b(t) \) be the number of copies for a book with title \( t \), then for a borrow operation, you must check that \( b(t) > 0 \) to allow borrowing.
inputFormat
The input is read from standard input and has the following format:
- An integer
N
representing the number of books initially in the library. N
lines follow, each containing a book title (a single word without spaces) and an integer indicating the number of copies available, separated by a space.- An integer
Q
representing the number of operations. Q
lines follow, each representing an operation. Each operation is one of the following formats:borrow <title>
return <title>
report
outputFormat
Output to standard output. For each operation, output a line based on the following:
- For
borrow
operations, print eitherBorrowed successfully
orBook not available
. - For
return
operations, printReturned successfully
. - For
report
operations, print a single line listing each book in the formattitle:count
separated by a space, sorted by title in lexicographic order.
2
BookA 2
BookB 0
5
borrow BookA
borrow BookB
return BookA
return BookC
report
Borrowed successfully
Book not available
Returned successfully
Returned successfully
BookA:2 BookB:0 BookC:1
</p>