Complicated Route
InterviewTime limit1sMemory limit128 MB
Parse a route of step counts in eight compass directions, sum the displacement, and print the final point and its distance from the origin to three decimals.
- Level
Easy3 of 10
- Topics
- Implementation, Math, Simulation, Geometry
- Solved
- No attempts yet
Problem
The citizens of Prague are preparing for the Summit too. Most importantly, they must be ready for the limited possibilities of moving through the city. The Home Affairs Department issued ten recommendations on how to behave (the so-called "decalogue"). One of these points says to obey the directions of the police, even when they recommend more complicated routes to the place a person wants to walk to.
The directions describing a route usually tell us something like "Start at this corner. Take three steps towards the tall chimney, then seventeen steps towards the small maple tree, ... blah blah ..., finally six steps towards the graffiti painting. Then you will be there." Most of these directions simply boil down to taking the mentioned number of steps in one of the eight principal compass directions (depicted in the figure).

Obviously, following the paths given by the police may lead to an interesting tour of the local scenery, but if you are in a hurry there is usually a much faster way: just march directly from your starting point to the place where you want to go. Instead of taking three steps north, one step east, one step north, three steps east, two steps south and one step west (see figure), following the direct route (the dashed line in the figure) results in a path of about 3.6 steps.
You are to write a program that computes the location of, and the distance to, the target place, given a recommended route.
Disclaimer: Note that this problem is not a challenge to violate the police recommendations! We take no responsibility for any improper use of the program.
Input
The input contains several strings, each on a line by itself and each consisting of at most 200 characters. The last string is "END", signaling the end of the input. Every other string describes one route in the following format.
The description is a comma-separated list of (length, direction) pairs. A length is a positive integer less than 10000, and a direction is one of "N" (north), "NE" (northeast), "E" (east), "SE" (southeast), "S" (south), "SW" (southwest), "W" (west), or "NW" (northwest). For example, "3W" means 3 steps to the west, and "17NE" means 17 steps to the northeast. A full stop (".") terminates the description, which contains no blanks.
Output
For every route description in the input, output a single line containing the sentence "You can go to (X,Y), the distance is D steps.", where X and Y are the absolute coordinates of the target point of the route. The coordinate system is oriented so that the x-axis points east and the y-axis points north. The path always starts at the origin (0,0). The real values X, Y, and D must be printed exact to three digits after the decimal point.