#C12866. Booking System Implementation

    ID: 42340 Type: Default 1000ms 256MiB

Booking System Implementation

Booking System Implementation

You are required to implement a booking system that supports reserving a time slot, canceling a booking, checking the availability of a slot, and listing all current bookings. The system only operates between time 0 to 24, and every booking must satisfy ( start < end ), with ( 0 \leq start ) and ( end \leq 24 ). A booking is valid if it does not overlap any existing booking (i.e. for any two bookings ((s_1, e_1)) and ((s_2, e_2)), the condition ( \max(s_1, s_2) < \min(e_1, e_2) ) indicates an overlap). Your system should also cancel bookings if an exact match is found and list all bookings in sorted order.

The input is given as a series of commands detailed below. Your solution should read from standard input and print the correct messages 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, which can be one of the following:

  • BOOK start end - Attempt to book a slot from start to end.
  • CANCEL start end - Cancel the booking from start to end.
  • IS_AVAILABLE start end - Check if the given slot is available. Outputs either True or False.
  • GET_ALL - Print all current bookings in chronological order in the format: [(s1, e1), (s2, e2), ...].
All numeric values are integers.

outputFormat

For each command, output the corresponding result on a separate line. The expected outputs are:

  • BOOK: Output one of "Booking successful.", "Invalid booking time.", or "Slot overlaps with an existing booking.".
  • CANCEL: Output either "Booking cancelled." or "Booking not found.".
  • IS_AVAILABLE: Output "True" or "False".
  • GET_ALL: Output the list of bookings as a Python-style list of tuples. For example, if there are bookings from 9 to 12 and 13 to 15, output "[(9, 12), (13, 15)]"; if no bookings exist, output "[]".
## sample
6
BOOK 9 12
BOOK 13 15
IS_AVAILABLE 10 11
IS_AVAILABLE 12 13
GET_ALL
CANCEL 9 12
Booking successful.

Booking successful. False True [(9, 12), (13, 15)] Booking cancelled.

</p>