Movie Ticket Booking
Book seats for a movie show: register shows with a seat grid, reserve individual seats (no double-booking), and report how many seats are left.
Requirements
addShowregisters a show with arows×colsgrid of seats, all initially free. Show ids are distinct.- Seats are addressed as
R<row>C<col>, 1-indexed (e.g.R2C3is row 2, column 3). Parse the token exactly: an uppercaseR, one or more digits, an uppercaseC, one or more digits, and nothing else — anything that doesn't match this shape is invalid. bookreturnstrueonly when the show exists, the token is well-formed, the seat is in range, and it is currently free; it then marks that seat booked. Every other case (malformed token, out-of-range seat, already-booked seat, unknown show) returnsfalseand changes nothing.availablereturns the number of free seats and 0 for an unknown show.
API to implement
Implement the class MovieBooking. The I/O driver is already written in the starter code — it parses the command script below and calls your methods. You only implement the class.
| Command | Returns | Behavior |
|---|---|---|
| addShow <showId> <rows> <cols> | — | Register show showId with a rows×cols grid of seats, all initially free. Show ids are distinct. |
| book <showId> <seat> | boolean | Reserve seat (like R2C3, 1-indexed) in show showId. Returns true only if the show exists, the token is well-formed, the seat is in range, and it is currently free — then marks it booked. Any other case (bad format, out of range, already booked, unknown show) returns false. |
| available <showId> | int | Number of free seats in show showId. Returns 0 for an unknown show. |
Input format
The first line contains Q, the number of operations. Each of the next Q lines is one command as listed above. String arguments contain no spaces.
Output format
For each command with a non-void return, print its result on its own line, in order. The driver does this for you — your methods just return values.
This is a design problem: the hidden tests exercise edge cases and interaction sequences, not performance tricks. Model the state cleanly and the tests will pass.
Sample cases
7
addShow 1 2 3
available 1
book 1 R1C1
available 1
book 1 R1C1
book 1 R2C3
available 16
true
5
false
true
47
addShow 7 2 2
book 7 R3C1
book 7 R1C3
book 7 R0C1
book 7 XYZ
book 7 R1C1
available 7false
false
false
false
true
3