#K89042. Final Position on Grid
Final Position on Grid
Final Position on Grid
You are given a grid of size \(m \times n\). In this grid, the rows and columns are numbered from 0 to \(m-1\) and 0 to \(n-1\) respectively. A character is initially positioned at \((x, y)\). You will be given a sequence of commands to move the character. The commands are:
- U: Move up (decrease \(x\) by 1)
- D: Move down (increase \(x\) by 1)
- L: Move left (decrease \(y\) by 1)
- R: Move right (increase \(y\) by 1)
If executing a command would take the character outside the grid, that command is ignored. Your task is to simulate all the moves and determine the final position of the character.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains four space-separated integers \(m\), \(n\), \(x\), and \(y\), which represent the number of rows, the number of columns, and the starting row and column respectively.
- The second line contains a string of commands (each character is either U, D, L, or R).
outputFormat
Output the final position of the character, as two space-separated integers, to standard output (stdout).
## sample3 4 0 0
RRDD
2 2