結果

問題 No.104 国道
ユーザー SagTokiSagToki
提出日時 2018-05-16 14:54:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 1,563 bytes
コンパイル時間 3,584 ms
コンパイル使用メモリ 78,600 KB
実行使用メモリ 41,416 KB
最終ジャッジ日時 2024-06-28 13:19:35
合計ジャッジ時間 6,681 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,216 KB
testcase_01 AC 123 ms
40,080 KB
testcase_02 AC 128 ms
41,416 KB
testcase_03 AC 116 ms
40,084 KB
testcase_04 AC 115 ms
39,948 KB
testcase_05 AC 117 ms
40,016 KB
testcase_06 AC 112 ms
39,940 KB
testcase_07 AC 123 ms
41,180 KB
testcase_08 AC 110 ms
40,000 KB
testcase_09 AC 115 ms
40,028 KB
testcase_10 AC 113 ms
40,136 KB
testcase_11 AC 124 ms
41,112 KB
testcase_12 AC 111 ms
40,028 KB
testcase_13 AC 131 ms
41,408 KB
testcase_14 AC 117 ms
40,264 KB
testcase_15 AC 126 ms
40,980 KB
testcase_16 AC 123 ms
41,268 KB
testcase_17 AC 126 ms
41,092 KB
testcase_18 AC 119 ms
39,988 KB
testcase_19 AC 126 ms
41,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class NationalHighway {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        try{
            String string = scanner.nextLine();
            if(string.length() != 0){
                Pattern pattern = Pattern.compile(".*[R|L| ].*");
                Matcher matcher = pattern.matcher(string);
                if(!matcher.find()){
                    System.out.println("文字列はRかLだけで入力してください");
                    System.exit(0);
                }
                if(string.length()<0 || string.length() > 30){
                    System.out.println("文字列は1以上30以下で入力してください");
                }
            }
            
            int Road = 1;
            char[] NewString = string.toCharArray();
             
            for(int i = 0 ; i < string.length() ; i++){
                //System.out.print("test");
                if(NewString[i] == 'R'){
                    Road = Road * 2 + 1;
                }else if(NewString[i] == 'L'){
                    Road = Road * 2 ;
                }else{
                    //何もしない
                }
            }
            System.out.println(Road);
            
        }catch(InputMismatchException e){
            System.out.println("");
        }catch(Exception E){
            System.out.println("予期せぬエラーです");
        }
    }
}
0