Lazy pirate captain
Statement
Goal
You are the captain of a pirate ship, taking some downtime in the tavern to rest and find fresh sources of booty. You just bought a parchment with directions to a buried treasure.It tells you where to start (x and y coordinates on the X and Y axes of a two-dimensional Cartesian plane), and then has a series of n travel legs in cardinal direction dir for distance dist.
dir is one of: "N", "S", "E", or "W".
"N" means north, i.e. travel in the positive direction along the Y axis.
"S" means south, i.e. travel in the negative direction along the Y axis.
"E" means east, i.e. travel in the positive direction along the X axis.
"W" mean west, i.e. travel in the negative direction along the X axis.
You don't feel like doing all that sailing, so you pull out your map to figure out where the treasure is and go directly there instead.
Input
Line 1: x y two integers separated by a space, the starting coordinates.
Line 2: n, a positive integer, the number of travel legs.
Next n lines: A character dir and positive integer dist, the direction and distance to travel.
Line 2: n, a positive integer, the number of travel legs.
Next n lines: A character dir and positive integer dist, the direction and distance to travel.
Output
Line 1: The final coordinates x and y separated by a space.
Constraints
Example
Input
0 0 1 N 1
Output
0 1
Game modes
Fastest, Shortest, Reverse
Test cases
One step Test
Input
0 0
1
N 1
Output
0 1
Validator 1 Validator
Input
4 2
1
N 1
Output
4 3
Around the block Test
Input
0 0
4
N 1
E 1
S 1
W 1
Output
0 0
Validator 2 Validator
Input
8 7
4
N 1
E 1
S 1
W 1
Output
8 7
Eastbound and down Test
Input
-12 -8
2
E 10
S 3
Output
-2 -11
Validator 3 Validator
Input
-12 -8
2
W 10
N 3
Output
-22 -5
Country roads Test
Input
-33 18
8
W 100
S 100
E 100
N 100
E 100
N 100
W 100
S 100
Output
-33 18
Validator 4 Validator
Input
-33 18
8
W 1000
S 1000
E 1000
N 1000
E 1000
N 1000
W 1000
S 1000
Output
-33 18
Solution language
Solution
Stub generator input