#C11998. Airline Reservation System

    ID: 41375 Type: Default 1000ms 256MiB

Airline Reservation System

Airline Reservation System

You are required to implement a reservation management system for handling booking requests, cancellations, and seat queries for airline flights. Each flight starts with 500 available seats. The system should process commands read from standard input.

The system supports three types of operations:

  • book flight_id seat_number: Attempt to book a seat seat_number on flight flight_id. Output "SUCCESS" if the seat is successfully booked, otherwise output "FAIL".
  • cancel flight_id seat_number: Attempt to cancel the booking for seat seat_number on flight flight_id. Output "SUCCESS" if the cancellation is successful, otherwise output "FAIL".
  • query flight_id: Output the number of available seats on flight flight_id. If the flight has no prior bookings, it starts with 500 available seats.

All operations should be processed sequentially as they appear in the input.

inputFormat

The input is given via standard input. The first line contains a single integer n representing the number of operations. The following n lines each contain one operation in one of the following formats:

  • book flight_id seat_number
  • cancel flight_id seat_number
  • query flight_id

Note that seat_number is a positive integer and flight_id is a string with no spaces.

outputFormat

For each operation read from the input, output the corresponding result on a separate line, in the same order as the input operations. For the book and cancel operations, output either "SUCCESS" or "FAIL". For the query operation, output the number of available seats (an integer).

## sample
5
book flightA 1
book flightA 1
cancel flightA 1
cancel flightA 1
query flightA
SUCCESS

FAIL SUCCESS FAIL 500

</p>