TTC '18 Contest 2 P2 - Forward and Turn

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Ninjaclasher is playing with a toy tank. He places it on a grid, the initial location of the tank being (x_0, y_0).

Then, he gives the tank a series of instructions S, consisting of two kinds of letters, executed in order from front to back:

  • F: Move in the current direction by distance 1.
  • T: Turn 90 degrees clockwise.

Ninjaclasher has a simple question for you to answer: At what position will the tank stop at?

The tank will start facing up (if the instruction were F, the next position would be (x_0, y_0+1)).

Input Specification

The first line will contain N (1 \le N \le 100), the number of instructions Ninjaclasher's tank will have.

The second line of input will contain two space separated integers x_0 and y_0 (-1000 \le x_0, y_0 \le 1000), the initial position of the tank.

The last line of input will contain a string S, consisting of only F and T as characters.

Output Specification

The one and only line of output will contain 2 space-separated integers, x_e and y_e, the ending position of the tank.

Sample Input 1

5
0 0
FFTFT

Sample Output 1

1 2

Sample Input 2

5
1 1
FFTFT

Sample Output 2

2 3

Comments

There are no comments at the moment.