#K83302. Final Robot Position
Final Robot Position
Final Robot Position
This problem involves simulating the moves of a robot on a 2D plane. The robot starts at the origin \((0,0)\) and can move in four directions: "UP", "DOWN", "LEFT", and "RIGHT". For each test case, you are given an integer \(N\) representing the number of commands, followed by \(N\) commands. Determine the final position \((x, y)\) of the robot after executing all commands.
Movement Rules:
- "UP": Increment \(y\) by 1.
- "DOWN": Decrement \(y\) by 1.
- "LEFT": Decrement \(x\) by 1.
- "RIGHT": Increment \(x\) by 1.
Example: For a test case with commands: UP LEFT DOWN
, the robot moves from \((0,0)\) to \((0,1)\), then \((-1,1)\), and finally \((-1,0)\). Hence, the final position is \((-1, 0)\).
inputFormat
The first line contains an integer \(T\), the number of test cases. Each test case consists of two lines:
- The first line contains an integer \(N\), the number of commands.
- The second line contains \(N\) space-separated strings, each being one of the commands: "UP", "DOWN", "LEFT", "RIGHT".
outputFormat
For each test case, output a single line with two space-separated integers representing the final \(x\) and \(y\) coordinates of the robot.
## sample2
3
UP LEFT DOWN
4
RIGHT UP UP LEFT
-1 0
0 2
</p>