#K58667. Final Position in a Grid
Final Position in a Grid
Final Position in a Grid
Given a grid with dimensions \(M\times N\), determine the final position after performing a sequence of moves starting from the position \((X, Y)\). The grid is 0-indexed with row indices ranging from 0 to \(M-1\) and column indices from 0 to \(N-1\). Each move is represented by a character: 'L' (left), 'R' (right), 'U' (up), and 'D' (down). When a move would cause the position to go out of bounds, that move is skipped.
Your task is to compute the final coordinates after executing all given moves.
inputFormat
The input is given in two lines:
- The first line contains four space-separated integers: \(M\), \(N\), \(X\), and \(Y\), representing the number of rows, number of columns, and the starting row and column respectively.
- The second line contains a string of moves composed solely of the characters 'L', 'R', 'U', and 'D'. This string may be empty.
outputFormat
Output a single line with two space-separated integers indicating the final row and column positions.
## sample5 5 1 2
LRRUDD
2 3