#C13355. Theater Ticket Booking Simulation
Theater Ticket Booking Simulation
Theater Ticket Booking Simulation
You are given a theater seating arrangement represented as a grid with rows and columns. All seats are initially available, denoted by the character A
. Your task is to implement a ticket booking system that supports three types of operations:
- B r c: Book the seat at row
r
and columnc
. If the seat is available (A
), mark it as booked (B
) and outputTrue
; otherwise, outputFalse
. - C r c: Cancel the booking of the seat at row
r
and columnc
. If the seat is booked (B
), mark it as available (A
) and outputTrue
; otherwise, outputFalse
. - D: Display the current seating plan. The seating plan should be printed as
rows
lines of a string with each row represented continuously (i.e. without spaces), where each character is eitherA
(available) orB
(booked).
Note that the seat indices are 0-indexed (i.e. the first row/column is numbered 0).
The operations must be processed in the order they appear in the input.
In mathematical notation, let the seat at row i and column j be denoted by \(S_{i,j}\). Initially, \(S_{i,j} = A\) for all valid \(i,j\). A booking operation changes \(S_{r,c}\) from \(A\) to \(B\) if \(S_{r,c} = A\), and a cancellation changes \(S_{r,c}\) from \(B\) to \(A\) if \(S_{r,c} = B\). Invalid indices or operations on seats already in the desired state should produce False
as output.
inputFormat
The input is read from stdin
and has the following format:
rows cols Q op1 op2 ... opQ
Here, rows and cols are the dimensions of the theater, and Q is the number of operations. Each of the next Q lines defines an operation:
B r c
for booking a seat,C r c
for cancellation, orD
for displaying the seating arrangement.
Note that r
and c
are integers.
outputFormat
For each operation, output the following to stdout
:
- For a booking (
B
) or cancellation (C
) operation, outputTrue
orFalse
on a new line. - For a display (
D
) operation, output the current seating arrangement asrows
lines. Each line represents a row without spaces.
The outputs for consecutive operations should appear in the order they are processed.
## sample3 3
5
D
B 1 1
B 1 1
D
C 1 1
AAA
AAA
AAA
True
False
AAA
ABA
AAA
True
</p>