結果

問題 No.113 宝探し
ユーザー SagTokiSagToki
提出日時 2018-05-16 17:13:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 114 ms / 5,000 ms
コード長 1,756 bytes
コンパイル時間 3,717 ms
コンパイル使用メモリ 77,784 KB
実行使用メモリ 41,472 KB
最終ジャッジ日時 2024-04-28 08:13:50
合計ジャッジ時間 6,742 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
39,844 KB
testcase_01 AC 106 ms
41,028 KB
testcase_02 AC 98 ms
40,072 KB
testcase_03 AC 99 ms
40,444 KB
testcase_04 AC 109 ms
41,100 KB
testcase_05 AC 114 ms
41,472 KB
testcase_06 AC 113 ms
40,884 KB
testcase_07 AC 109 ms
41,312 KB
testcase_08 AC 105 ms
41,280 KB
testcase_09 AC 105 ms
41,000 KB
testcase_10 AC 105 ms
41,040 KB
testcase_11 AC 99 ms
40,068 KB
testcase_12 AC 101 ms
40,620 KB
testcase_13 AC 97 ms
40,240 KB
testcase_14 AC 109 ms
41,164 KB
testcase_15 AC 111 ms
41,272 KB
testcase_16 AC 113 ms
41,220 KB
testcase_17 AC 96 ms
40,076 KB
testcase_18 AC 108 ms
41,244 KB
testcase_19 AC 105 ms
41,260 KB
testcase_20 AC 107 ms
41,136 KB
testcase_21 AC 108 ms
41,016 KB
testcase_22 AC 107 ms
41,200 KB
testcase_23 AC 106 ms
41,140 KB
testcase_24 AC 108 ms
41,004 KB
testcase_25 AC 111 ms
41,444 KB
testcase_26 AC 108 ms
41,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.InputMismatchException;

public class TreasureHunt {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        try{
            String S = scanner.next();
            Pattern pattern = Pattern.compile("./[N|E|W|S]./");
            Matcher matcher = pattern.matcher(S);
            if(matcher.find()){
                System.out.println("文字列はN,E,W,Sの中から選択してください");
                System.exit(0);
            }
            if(S.length() < 1 || S.length() > 100){
                System.out.println("文字列の長さは1以上100以下で入力してください");
                System.exit(0);
            }
            
            int X = 0;
            int Y = 0;
            char[] CS = S.toCharArray();
            
            for(int i = 0 ; i < S.length() ; i++){
                switch(CS[i]){
                    case 'N':
                        Y++;
                        break;
                    case 'E':
                        X++;
                        break;
                    case 'W':
                        X--;
                        break;
                    case 'S':
                        Y--;
                        break;
                }
            }
            X = Math.abs(X);
            Y = Math.abs(Y);
            
            System.out.println(Math.pow(Math.pow(X,2) + Math.pow(Y, 2), 0.5));
            
            
        }catch(InputMismatchException e){
            System.out.println("");
        }catch(Exception E){
            System.out.println("想定外のエラーです");
        }
    }           
}
0