#C9628. Ticket Booking System
Ticket Booking System
Ticket Booking System
This problem requires you to simulate a simple ticket booking system for a movie theater. You need to implement a system that supports the following operations:
book c k
: Book k tickets under the customer name c.cancel c k
: Cancel k tickets for customer c. If the cancellation number exceeds the current booking, set the ticket count for that customer to 0.check c
: Print the number of tickets currently booked under customer name c.summary
: Print a summary report where the first output line shows the total number of tickets booked, i.e. $S=\sum_{c}\text{tickets}(c)$, and the following lines list each customer with a positive ticket count in alphabetical order in the format customer: tickets.
You must read input from standard input and output the results to standard output.
inputFormat
The input begins with an integer n
representing the number of operations to process. The following n
lines each contain one of the following commands:
book c k
: Bookk
tickets for customerc
.cancel c k
: Cancelk
tickets for customerc
.check c
: Output the number of tickets booked by customerc
.summary
: Output the summary of all bookings.
Parameters are space-separated. Customer names are strings without spaces and k
is a positive integer.
outputFormat
For each operation that produces an output (check
and summary
), output the result in the order that the operations are given. For a check
operation, output a single integer representing the number of tickets booked for that customer. For a summary
operation, output multiple lines: the first line must be the total number of booked tickets, followed by each customer (with a positive ticket count) in alphabetical order; each line should be formatted as customer: tickets
.
4
book Alice 5
check Alice
cancel Alice 2
check Alice
5
3
</p>