#C10952. Final Position after Movement Instructions
Final Position after Movement Instructions
Final Position after Movement Instructions
You are given an integer T
representing the number of test cases. For each test case, a string of instructions is provided. Each instruction is one of the characters L
, R
, U
, or D
which indicate moving left, right, up, and down respectively. Initially, you start at the origin (0, 0).
The movement rules are defined as follows: $$L: x = x-1$$, $$R: x = x+1$$, $$U: y = y+1$$, and $$D: y = y-1$$. For each test case, you need to compute the final coordinates after executing the sequence of instructions and output the result in the format x y
on a new line for each case.
Ensure your solution reads from standard input and writes to standard output.
inputFormat
The first line of input contains an integer T
(the number of test cases). Each of the next T
lines contains a non-empty string consisting only of the characters L
, R
, U
, and D
, representing the sequence of movement instructions.
outputFormat
For each test case, print a single line with two space-separated integers representing the final x and y coordinates after processing the instructions.
## sample2
LLRR
UUDDLR
0 0
0 0
</p>