Compass Rose

면접 대비

시간 제한1초메모리 제한2048 MB

요약
카디널 문자를 앞에 붙여 만든 WSW 같은 방위 표기를 정확한 각도로 변환한다.
난이도

보통10점 중 4점

유형
구현, 문자열, 수학, 재귀
정답자
아직 제출이 없습니다

문제

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∘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.

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

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

  • \item Headings of length n≥3n \geq 3 are composed of a valid heading of length n−1n - 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∘45^{\circ}) but would like to add more specificity. We can prepend either N to form NNE (22.5∘22.5^{\circ}, halfway between 0∘0^{\circ} and 45∘45^{\circ}) or E to form ENE (67.5∘67.5^{\circ}, halfway between 90∘90^{\circ} and 45∘45^{\circ}).

    Similarly, we can form NNNE (12.25∘12.25^{\circ}, halfway between 0∘0^{\circ} and 22.5∘22.5^{\circ}) and ENNE (33.75∘33.75^{\circ}, halfway between 22.5∘22.5^{\circ} and 45∘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.

입력

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

출력

You should output nn lines, with the ithi^{\text{th}} line containing a real number, the compass heading (in degrees) corresponding to the given heading D_iD\_i.

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

예제2

  1. 예제 1

    입력
    2
    W
    N
    
    예상 출력
    270
    0
    
  2. 예제 2

    입력
    6
    NW
    ESE
    ENNE
    SESE
    WNNNW
    WWWSW
    
    예상 출력
    315.0
    112.5
    33.75
    123.75
    343.125
    264.375