A common stack, queue problem

xiaoxiao2021-03-06  56

[Problem Description] There is a narrow parking lot that can park N cat, and it only has a door to enter and exit. The vehicle is parked from the parking lot in the parking lot in the morning and evening of the parking lot (the first car that arrives in the parking lot). If the parking lot has been filled with N cars, the later vehicles can only wait in the parking lot outside the parking lot. Once there is a car in the parking lot, the first vehicle in the road is entered the parking lot. If there is a car to drive within the parking lot, after it enters the parking lot, you must first withdraw from the parking lot to let the road, wait until the parking lot, these vehicles are re-entered in the original order. Each car should be short-spent based on its time for time to stay in the parking lot. If you stay in the parking road, you have to leave, allow it to leave, no parking fee, and still maintain the sequence of vehicles waiting on the prison. Prepare a program to simulate the management of the parking lot. [Implementation requirements] Require program to output a parking position after the arrival of each car (parking lot or lodging), and the cost of paying when a car leaves the parking lot and its time to stay in the parking lot

[My prompt] The analog input format of the car can be: (arrived / depart, car license, reaching / leaving time). For example, ('A', 1, 5) means that the No. 1 license is reached at 5 this moment, and ('d', 5, 20) means that the No. 5 license is allowed at 20. The entire program can end when the input information is ('e', 0, 0). This article can be implemented in stacks and queues.

转载请注明原文地址:https://www.9cbs.com/read-118176.html

New Post(0)