#C5352. Parking Lot Simulation

    ID: 48992 Type: Default 1000ms 256MiB

Parking Lot Simulation

Parking Lot Simulation

In this problem, you are given a parking lot represented as a grid with (n) rows and (m) columns. Each cell in the grid is either 'E' (representing an empty parking space) or 'C' (representing an occupied parking space). Cars arrive sequentially. For each arrival, you must park the car in the nearest available empty parking space. The "nearest" empty space is defined as the first cell containing 'E' when scanning the grid row by row from top to bottom and within each row from left to right. If no empty space is found, the parking lot remains unchanged.

After each car is parked, output the current state of the parking lot. Each test case consists of a parking lot configuration followed by the number of car arrivals. The input will contain multiple test cases. The end of input is indicated by a line with two zeros: "0 0".

Note: The grid is represented in plain text where each row is on a new line. After processing each arrival, print the updated grid followed by an empty line.

inputFormat

The input consists of multiple test cases. Each test case begins with a line containing two integers (n) and (m) (separated by a space) representing the number of rows and columns of the parking lot grid. It is followed by (n) lines, each containing a string of length (m) representing a row of the parking lot ('E' for empty, 'C' for car). The next line contains an integer representing the number of car arrivals. The input terminates with a line containing "0 0".

outputFormat

For each car arrival in a test case, print the parking lot grid after parking the car. Each row of the grid should be printed on a separate line. After printing the grid for an arrival, print an empty line. Process all arrivals for each test case until the termination input is encountered.## sample

4 5
EEEEE
ECECE
EEEEE
ECEEE
3
0 0
CEEEE

ECECE EEEEE ECEEE

CCEEE ECECE EEEEE ECEEE

CCCEE ECECE EEEEE ECEEE

</p>