結果

問題 No.113 宝探し
ユーザー YukimotoPGYukimotoPG
提出日時 2019-02-14 21:59:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 674 bytes
コンパイル時間 2,597 ms
コンパイル使用メモリ 71,168 KB
実行使用メモリ 56,640 KB
最終ジャッジ日時 2023-08-10 15:21:59
合計ジャッジ時間 6,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
55,696 KB
testcase_01 AC 113 ms
55,756 KB
testcase_02 AC 111 ms
55,640 KB
testcase_03 AC 114 ms
55,300 KB
testcase_04 AC 112 ms
55,692 KB
testcase_05 AC 111 ms
55,796 KB
testcase_06 AC 111 ms
55,252 KB
testcase_07 AC 114 ms
56,024 KB
testcase_08 AC 109 ms
56,136 KB
testcase_09 AC 111 ms
56,188 KB
testcase_10 AC 112 ms
55,736 KB
testcase_11 AC 111 ms
53,756 KB
testcase_12 AC 110 ms
55,700 KB
testcase_13 AC 113 ms
55,348 KB
testcase_14 AC 111 ms
56,160 KB
testcase_15 AC 111 ms
55,776 KB
testcase_16 AC 109 ms
55,448 KB
testcase_17 AC 113 ms
55,960 KB
testcase_18 AC 110 ms
55,488 KB
testcase_19 AC 112 ms
56,640 KB
testcase_20 AC 111 ms
55,820 KB
testcase_21 AC 114 ms
56,104 KB
testcase_22 AC 113 ms
56,064 KB
testcase_23 AC 112 ms
55,564 KB
testcase_24 AC 112 ms
55,636 KB
testcase_25 AC 115 ms
55,904 KB
testcase_26 AC 113 ms
55,800 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