No.113 Treasure Hunt
タグ : / 解いたユーザー数 694
作問者 :
nmnmnmnmnmnmnm
Problem Statement
A-kun has obtained a treasure map.
The map shows a park, with a mark drawn at the center of the park.
It also describes how to move from there.
The movement corresponding to each written character is as follows.
・"N" means move 1 meter north.
・"E" means move 1 meter east.
・"W" means move 1 meter west.
・"S" means move 1 meter south.
For example, if "NE" is written, walk 1 meter north and then walk 1 meter east.
It seems that digging at that point will reveal the treasure.
However, A-kun noticed that these movements are wasteful.
For "NE", it seems sufficient to move just $\sqrt{1^2+1^2}=\sqrt{2}$ meters in the northeast direction.
A-kun wants to move from the center of the park to the location where the treasure is buried by the shortest distance.
Assuming there is no possibility of running into obstacles, how many meters does A-kun need to move?
Input
$S$
The string $S$ written on the map is given in one line.
The length of the string $S$ is at least 1 character and at most 100 characters.
The string consists only of the 4 characters 'N','E','W','S'.
Output
Output the distance from the center of the park to the location where the treasure is buried in one line. An error of up to ±0.01 is allowed.
Do not forget the newline at the end.
Sample
Sample 1
Input
NE
Output
1.41421
This is the same as the example in the problem statement.
Sample 2
Input
EN
Output
1.41421
Walk 1 meter east and then walk 1 meter north.
This ends up at the same location as in Sample 1, so the answer is the same as Sample 1.
Sample 3
Input
SSSSWWW
Output
5
The final position is 4 meters south and 3 meters west.
Therefore, the answer is $\sqrt{4^2+3^2}=5$ meters.
Sample 4
Input
ESSSSEWENWNNEWWEESSS
Output
4.47214
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。