#K15356. Parking Lot Management System
Parking Lot Management System
Parking Lot Management System
Design a parking lot system to manage parking for cars in a multi-level parking lot. The parking lot contains \(L\) levels with \(S\) spots on each level. When parking a car, it should be placed at the lowest available level and the first available spot on that level. If all spots are taken, the system must return "Parking lot full". Cars can be removed from specified positions. Additionally, you should be able to query the number of available spots on each level.
The system should support the following operations:
- park: Parks a car. Returns "Car parked on level X, spot Y" if successful, or "Parking lot full" if no spot is available.
- remove L S: Removes a car from level L and spot S. Returns "Car removed from level L, spot S" if there was a car, or "No car in level L, spot S" otherwise.
- query: Outputs the number of available spots on each level separated by a space.
The key invariant is that a car is always parked in the lowest level with an available spot. Mathematically, if the total number of spots is \(T = L \times S\) and \(p\) cars have been parked, the number of available spots is \(T - p\), distributed across levels based on the parking order.
inputFormat
The input is read from stdin and has the following format:
L S N command_1 command_2 ... command_N
Where:
- L and S are integers representing the number of levels and the number of parking spots per level respectively.
- N is the number of commands to process.
- Each command is on a new line and can be:
- park - to park a car.
- remove L S - to remove a car from a specific level (L) and spot (S).
- query - to print the available spots on each level (space separated).
outputFormat
For each command, output the corresponding result to stdout on its own line. The outputs are as follows:
- For park: print "Car parked on level X, spot Y" or "Parking lot full".
- For remove: print "Car removed from level X, spot Y" or "No car in level X, spot Y".
- For query: print the available spots on each level as space separated integers.
3 5
7
park
park
query
park
park
park
query
Car parked on level 1, spot 1
Car parked on level 1, spot 2
3 5 5
Car parked on level 1, spot 3
Car parked on level 1, spot 4
Car parked on level 1, spot 5
0 5 5
</p>