#C5119. Parking Lot Simulation
Parking Lot Simulation
Parking Lot Simulation
You are required to implement a parking lot simulation system. The parking lot has a fixed capacity and supports the following operations:
- park <vehicle_id>: Park a vehicle with the given id. Return
True
if the parking is successful andFalse
if the parking lot is full. - leave <vehicle_id>: Remove the vehicle with the given id from the parking lot. Return
True
if the vehicle was present and removed, otherwise returnFalse
. - status: Print the current status of the parking lot. If there are parked vehicles, output a space separated list of sentences of the format: Vehicle X is parked. for each vehicle (in the order they were parked). If no vehicles are parked, output Parking lot is empty.
- getFreeSlots: Output the number of free slots remaining in the parking lot.
The system will process a series of operations given via standard input and produce the corresponding outputs to standard output.
Formally, let \( C \) be the capacity of the parking lot. For each operation, perform the action and print the result immediately. For a park or leave operation, print True
or False
as the result. For a status operation, output the status string and for a getFreeSlots operation, output a number.
Note: The order in which the vehicles are parked should be preserved in the status output.
inputFormat
The first line of input contains an integer \( C \), the capacity of the parking lot. The second line contains an integer \( N \), the number of operations to perform. The following \( N \) lines each contain an operation in one of the four formats:
park <vehicle_id>
leave <vehicle_id>
status
getFreeSlots
outputFormat
For each operation, output the result to standard output on a separate line:
- For park and leave operations, output
True
orFalse
. - For status, output the current status string. If there are parked vehicles, output a space separated series of phrases of the form
Vehicle X is parked.
for each parked vehicle; otherwise, outputParking lot is empty.
. - For getFreeSlots, output the number of available slots.
2
7
park 1001
park 1002
park 1003
status
leave 1001
park 1003
getFreeSlots
True
True
False
Vehicle 1001 is parked. Vehicle 1002 is parked.
True
True
0
</p>