結果

問題 No.113 宝探し
ユーザー YukimotoPGYukimotoPG
提出日時 2019-02-14 21:59:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 114 ms / 5,000 ms
コード長 674 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 74,336 KB
実行使用メモリ 41,548 KB
最終ジャッジ日時 2024-04-28 08:19:28
合計ジャッジ時間 5,543 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
40,312 KB
testcase_01 AC 102 ms
40,868 KB
testcase_02 AC 105 ms
41,020 KB
testcase_03 AC 108 ms
41,004 KB
testcase_04 AC 109 ms
41,208 KB
testcase_05 AC 107 ms
40,976 KB
testcase_06 AC 109 ms
41,340 KB
testcase_07 AC 105 ms
41,012 KB
testcase_08 AC 92 ms
39,832 KB
testcase_09 AC 107 ms
41,396 KB
testcase_10 AC 108 ms
40,764 KB
testcase_11 AC 106 ms
41,224 KB
testcase_12 AC 107 ms
41,248 KB
testcase_13 AC 112 ms
41,548 KB
testcase_14 AC 99 ms
40,088 KB
testcase_15 AC 98 ms
40,124 KB
testcase_16 AC 104 ms
40,868 KB
testcase_17 AC 97 ms
39,872 KB
testcase_18 AC 112 ms
41,244 KB
testcase_19 AC 112 ms
41,332 KB
testcase_20 AC 97 ms
40,568 KB
testcase_21 AC 103 ms
41,072 KB
testcase_22 AC 95 ms
40,040 KB
testcase_23 AC 114 ms
40,828 KB
testcase_24 AC 114 ms
41,052 KB
testcase_25 AC 113 ms
41,108 KB
testcase_26 AC 96 ms
40,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		String s = sc.next();
		int x = 0; int y = 0;
		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i) == 'N') y++;
			else if (s.charAt(i) == 'E') x++;
			else if (s.charAt(i) == 'W') x--;
			else y--;
		}
		System.out.println(calcEuclidDistance(0,0,x,y));
		
		
	}
	
	static int calcManhatDistance (int x1, int y1, int x2, int y2) {
		int d = Math.abs(x1-x2)+Math.abs(y1-y2);
		return d;
	}
	static double calcEuclidDistance (double x1, double y1, double x2, double y2) {
		double d = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
		return d;
	}
	
}
0