yukicoder No.113 宝探し

Problem

No.113 宝探し - yukicoder

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String S = reader.readLine();
        int x = 0;
        int y = 0;
        for (int i = 0; i < S.length(); i++) {
            switch (S.charAt(i)) {
                case 'N':
                    y += 1;
                    break;
                case 'E':
                    x += 1;
                    break;
                case 'W':
                    x -= 1;
                    break;
                case 'S':
                    y -= 1;
                    break;

            }
        }

        System.out.println(Math.sqrt(x*x + y*y));
    }
}
Remove all ads