407904: GYM102939 B Pathfinder

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Pathfindertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

Input

The 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.

Output

Print two space separated integers, x and y, giving the final x, y position that Robby ends in.

ExampleInput
6
F 1
R
F 2
L
L
F 4
Output
-2 1

加入题单

算法标签: