407904: GYM102939 B Pathfinder
Description
Robby is a path-finding robot and is very good at its job! Given a series of instructions of a path to follow (as how far forward to move based on current orientation or an instruction to turn left or right), Robby always follows these instructions perfectly.
Unfortunately, Robby's instruction following module is currently malfunctioning, so it'll need a software patch to figure out how to follow instructions once again. Can you write a program that given a series instructions figures out where Robby should end up?
Robby will initially start off facing north from the x, y position (0, 0). Robby can be given three types of instructions. First, if Robby is given the instruction F $$$i$$$ for some integer $$$i$$$, Robby will move forward $$$i$$$ spaces based on the direction it is currently facing. Next, if Robby is given the instruction L, Robby will turn 90 degrees to the left. Finally, if Robby is given the instruction R, Robby will turn 90 degrees to the right. Process all of the instructions given to Robby and output the final x, y position that Robby ends in.
InputThe first line of the input will consist of a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) giving the number of instructions that Robby must follow. The next $$$n$$$ lines consist of instructions as described above. If the instruction begins with an F, it will also contain a single integer $$$i$$$ ($$$1 \leq i \leq 100$$$) giving the distances Robby should travel forward. Otherwise the instruction will only consist of a single character L or R, indicating Robby should turn 90 degrees to the left or right, respectively.
OutputPrint two space separated integers, x and y, giving the final x, y position that Robby ends in.
ExampleInput6 F 1 R F 2 L L F 4Output
-2 1