Knockemdead Parking Garage Solution

Knockemdead Parking Garage Solution

The Knockemdead Parking Garage contains a single lane thatholds up to 6cars. Cars arrive at the south end of the garage and leave from the north end. If a customer arrives topick up a car that is not the northernmost, all cars to the north of his car are moved out, his car is driven out, and the other cars are restored in the same order that they were inoriginally. Whenever a car leaves, all cars to the south are moved forward so that at all times all the empty spaces are in the south part of the garage.

Write a program that reads a group of input lines. Each line contains an ‘a’ for arrival or a d’ for departure and a license plate number. Cars are assumed to arrive and depart in the order

specified by the input. The program should print a message eachtime that a car arrives or departs. When a car arrives, themessage should specify whether or not there is room in thegarage for the car. If there is no room for a car, the car then proceeds to the Bashemup garage…which is similar to theKnockemdead.

There is room for 6cars at the Bashemup Garage.Now…if both garages are filled up, cars wait in the streetnear the Knockemdead garage for a space..and of course they are queued up in the street as well. The street can hold only five cars. If more than 6 cars try to wait in the street the cars are told to go to BOSTON.

So in summary…when a car arrives it tries to park in the Knockemdead

If no room it goes to the Bashemup…If still no room it tries to park in the street

When a car departs a message should indicate where it departed from (i.e. which

garage or the street).

If there is a car waiting to get in the garage (because both are full) then the first car in the street queue must be moved into the garage that now has room and a message stating this must appear.

When a car exits either garage (but NOT the street) you must also display the NUMBER of times that each car was moved to allow other cars to leave the garage..DO NOT COUNT the move for the car to depart itself
Powered by