Under construction

Still being built. Things may change

There's treasure everywhere!

Time limit1sMemory limit128 MB

Summary
Parse a map of step counts and compass directions, compute the treasure's coordinates, and print the straight-line distance from the origin.
Level

Easy3 of 10

Topics
Simulation, Implementation, Math, Geometry
Solved
No attempts yet

Problem

Finding buried treasure is simple: all you need is a map! The pirates of the Caribbean were famous for their enormous buried treasures and their elaborate maps. A map usually reads like this: “Start at the lone palm tree. Take three steps toward the forest, then seventeen steps toward the small spring, …, and finally six steps toward the giant rock. Dig right here, and you will find my treasure!” Most of these directions simply mean taking the stated number of steps in one of the eight principal compass directions: north (N), northeast (NE), east (E), southeast (SE), south (S), southwest (SW), west (W), and northwest (NW).

Following such a map may lead to a scenic tour, but if you are in a hurry there is a much faster way: march straight from the starting point to the treasure. For example, instead of walking three steps north, one step east, one step north, three steps east, two steps south, and one step west, going directly to the destination covers a distance of only about 3.6063.606 steps.

Write a program that, given a traditional map, computes the location of the buried treasure and the straight-line distance to it.

Input

The input consists of several lines, each a single string of at most 200200 characters. The last line is END, which marks the end of the input and does not describe a map.

Every other line describes one treasure map in the following format: a comma-separated list of pairs, where each pair is a length (a positive integer less than 10001000) immediately followed by a direction. The directions are N (north), NE (northeast), E (east), SE (southeast), S (south), SW (southwest), W (west), and NW (northwest). For example, 3W means three steps west and 17NE means seventeen steps northeast. A full stop (.) terminates each description, which contains no spaces.

Output

For each map, first print a line Map #k, where k is the map's number starting from 11. Then print the treasure's absolute coordinates on the next line in the format:

The treasure is located at (x,y).

The coordinate system has the x-axis pointing east and the y-axis pointing north, and every path starts at the origin (0,0)(0,0). A diagonal step (NE, NW, SE, SW) has the same length as a cardinal step, so a step of length LL in a diagonal direction changes each of the two coordinates by L/2L/\sqrt{2}.

On the following line, print the straight-line distance from (0,0)(0,0) to the treasure in the format:

The distance to the treasure is d.

Print xx, yy, and dd with exactly three digits after the decimal point, rounding half to even. Separate the reports of consecutive maps with a blank line.

Examples3

  1. Example 1

    Input
    3N,1E,1N,3E,2S,1W.
    10NW.
    END
    
    Expected output
    Map #1
    The treasure is located at (3.000,2.000).
    The distance to the treasure is 3.606.
    
    Map #2
    The treasure is located at (-7.071,7.071).
    The distance to the treasure is 10.000.
    
  2. Example 2

    Input
    5E.
    END
    
    Expected output
    Map #1
    The treasure is located at (5.000,0.000).
    The distance to the treasure is 5.000.
    
  3. Example 3

    Input
    17NE.
    END
    
    Expected output
    Map #1
    The treasure is located at (12.021,12.021).
    The distance to the treasure is 17.000.