BlueBook
p108ex8 - Direction
Given an integer N (0 ≤ N < 360), print out the closest compass bearing to that integer if N is the bearing in degrees. If there is a tie, print the "smaller" of the two possible outputs.
The bearings arranged in increasing order of "size" are: N, E, S, W. This means choose N over E if the input is 45, and N over W when the input is 315.
Input
The input consists of an integer T (1 ≤ T ≤ 1000), denoting the number of test cases and then each line following consists of one integer N.
Output
Output the closest compass bearing according to the input.
Sample Input
2
45
180
Sample Output
N
S
All Submissions
Best Solutions
Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 22, 2008
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
E-135°
S-135°
W-45°
???
It seems to work fine with the sample test cases i give it!
N-45°
E-135°
S-135°
W-45°
Also the segment you picked for W happens to all be part of N
Similarly, there should be 90 different values of N for which your code returns "S", but you accept 135 different values.