#C5306. Elevator System Simulation
Elevator System Simulation
Elevator System Simulation
This problem simulates an elevator system in a multi-story building. Given the current floor of the elevator, its moving direction (either \(UP\) or \(DOWN\)), a list of requested floors, and the total number of floors in the building, your task is to compute the order in which the elevator will visit the requested floors.
The elevator operates such that when moving in the \(UP\) direction, it first serves all requests for floors above its current position in ascending order, and then, if there are any, it serves the lower floors in descending order. Similarly, when moving in the \(DOWN\) direction, it first serves all requests for floors below its current position in descending order, then serves any remaining requests in ascending order.
For example, if the elevator is on floor 5 moving UP with requests [1, 3, 7, 9]
in a building with 10 floors, it will first visit floors 7 and 9 (in ascending order) and then floors 3 and 1 (in descending order), yielding the order [7, 9, 3, 1]
.
inputFormat
The input is provided via standard input (stdin) in the following format:
- The first line contains an integer representing the current floor of the elevator.
- The second line contains a string, either "UP" or "DOWN", representing the elevator's current direction.
- The third line contains an integer \(n\) representing the number of floor requests.
- The fourth line contains \(n\) space-separated integers representing the requested floors.
- The fifth line contains an integer representing the total number of floors in the building.
outputFormat
Output the order in which the elevator will visit the floors as a space-separated list on a single line via standard output (stdout). If there are no requests, output an empty line.
## sample5
UP
4
1 3 7 9
10
7 9 3 1