Hide

Problem F
Compass Rose

/problems/mines23.compassrose/file/statement/en/img-0001.png
By Brosen commonswiki - Own work, CC BY 2.5, https://commons.wikimedia.org/w/index.php?curid=667281

Your friend Rose works as an intern at the United States Geologic Survey (USGS) on Mines campus. She has taken you up to a geological site in Boulder and given you some locations at which you are to take geological measurements. Her instructions to get to these locations include headings that you’re having trouble decoding. These headings are strings consisting of between one and ten cardinal directions (N, S, E, and W) and correspond to an angle that you can set your compass to, to travel in the right direction. For example, the heading WSW corresponds to the angle $247.5^{\circ }$. Rose’s instructions include a lot of these headings, but you don’t have their corresponding angles memorized, so you decide to write a quick script to do the conversions for you.

Headings are defined as follows.

  • Single character headings (N, S, E, and W) correspond to $0^{\circ }$, $180^{\circ }$, $90^{\circ }$, and $270^{\circ }$, respectively.

  • Two character headings (NE, NW, SE, SW) correspond to $45^{\circ }$, $315^{\circ }$, $135^{\circ }$, and $225^{\circ }$, respectively.

  • Headings of length $n \geq 3$ are composed of a valid heading of length $n - 1$, with one of the characters in that heading prepended to it, to add additional specificity to the heading.

    For example, we take the heading NE ($45^{\circ }$) but would like to add more specificity. We can prepend either N to form NNE ($22.5^{\circ }$, halfway between $0^{\circ }$ and $45^{\circ }$) or E to form ENE ($67.5^{\circ }$, halfway between $90^{\circ }$ and $45^{\circ }$).

    Similarly, we can form NNNE ($12.25^{\circ }$, halfway between $0^{\circ }$ and $22.5^{\circ }$) and ENNE ($33.75^{\circ }$, halfway between $22.5^{\circ }$ and $45^{\circ }$) from NNE by prepending N or E, respectively. However, we cannot prepend S or W (forming SNNE or WNNE) because NNE only contains the cardinal directions N and E, and so we can only prepend those characters to it.

Input

The first line of input contains $1 \leq n \leq 1\, 000$, the number of test cases to follow. Each of the following $n$ lines contains a heading $D$ such that $1 \leq |D| \leq 10$, that is, each heading will be at most $10$ characters. You may assume that all headings given follow the definition provided above, and there will not be any invalid headings.

Output

You should output $n$ lines, with the $i^{\text {th}}$ line containing a real number, the compass heading (in degrees) corresponding to the given heading $D_ i$.

Answers within $10^{-8}$ of the correct answer will be accepted. If a compass heading does not contain a decimal portion, it can be omitted.

Sample Input 1 Sample Output 1
2
W
N
270
0
Sample Input 2 Sample Output 2
6
NW
ESE
ENNE
SESE
WNNNW
WWWSW
315.0
112.5
33.75
123.75
343.125
264.375

Please log in to submit a solution to this problem

Log in