410422: GYM104020 F Failing Flagship
Description
Ahoy! You are sailing towards the next "Boats Are Pretty Cool" convention to sell your latest gadget: a new type of compass.
On a normal compass, it is difficult to read off the precise wind direction. However, your new type of compass lets you read off wind directions to a much higher precision! The display can display strings of at most $$$1000$$$ characters.
Unfortunately, you have encountered some bad weather. After a few hours of heavy winds and big waves, you can finally look at your compass again. You read off the wind direction $$$X$$$ you are going and know in which wind direction $$$Y$$$ you need to go. However, to make the ship turn you have to enter the degrees of the angle the ship has to make in the control system. What is the smallest turn, in degrees, you have to make to get back on the right course?
A wind direction can also consist of $$$k\geq 3$$$ letters $$$l_1l_2\ldots l_k$$$. In that case, the last two letters indicate one of the four two-letter wind directions, i.e., $$$l_{k-1}l_k \in \{\text{NE}, \text{SE}, \text{SW}, \text{NW}\}$$$ and the other letters are equal to one of these, i.e., $$$l_i \in \{l_{k-1}, l_k\}$$$ for all $$$i \leq k-2$$$. This wind direction points precisely in the middle of the following two wind directions:
- wind direction $$$l_2\ldots l_k$$$,
- the first wind direction of at most $$$k-1$$$ letters you encounter when starting in $$$l_2\ldots l_k$$$ and move along the circle towards $$$l_1$$$.
The input consists of:
- One line with two strings $$$X$$$ and $$$Y$$$ ($$$1 \leq |X|, |Y| \leq 1000$$$), indicating the wind directions as described above.
Output the smallest turn you have to make to go from direction $$$X$$$ to $$$Y$$$.
Your answer should have an absolute error of at most $$$10^{-6}$$$.
ExamplesInputN SOutput
180.00000000000000000000Input
NNE SSSEOutput
146.25000000000000000000Input
ENE NWOutput
112.50000000000000000000