#C10483. Robot Movement Simulation
Robot Movement Simulation
Robot Movement Simulation
You are given a grid with n rows and m columns. A robot starts at the top-left cell which is designated as (1,1). The robot receives a sequence of movement instructions consisting of the characters U
(up), D
(down), L
(left), and R
(right). The robot will move one cell in the corresponding direction for each instruction, but if an instruction would cause the robot to move outside the grid boundaries, that instruction is ignored.
Your task is to simulate the movement of the robot on the grid and determine its final position after executing all the instructions.
Note: The grid is 1-indexed, meaning the top-left cell is (1,1) and the bottom-right cell is (n, m).
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains two integers n and m (the number of rows and columns of the grid, respectively).
- The second line contains a string of movement instructions. This string may be empty, which means no movement.
For example:
3 3 RRDDLU
outputFormat
Output the final position of the robot as two space-separated integers representing the row and column respectively. The output is written to standard output (stdout).
For example:
2 2## sample
3 3
RRDDLU
2 2
</p>