結果

問題 No.104 国道
ユーザー SagTokiSagToki
提出日時 2018-05-16 14:54:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 1,563 bytes
コンパイル時間 3,522 ms
コンパイル使用メモリ 74,956 KB
実行使用メモリ 55,956 KB
最終ジャッジ日時 2023-09-10 22:20:28
合計ジャッジ時間 6,958 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,496 KB
testcase_01 AC 125 ms
55,816 KB
testcase_02 AC 126 ms
55,368 KB
testcase_03 AC 126 ms
55,648 KB
testcase_04 AC 124 ms
55,736 KB
testcase_05 AC 124 ms
55,684 KB
testcase_06 AC 124 ms
55,648 KB
testcase_07 AC 126 ms
55,556 KB
testcase_08 AC 126 ms
55,844 KB
testcase_09 AC 127 ms
55,592 KB
testcase_10 AC 124 ms
55,956 KB
testcase_11 AC 127 ms
55,740 KB
testcase_12 AC 126 ms
55,656 KB
testcase_13 AC 128 ms
55,644 KB
testcase_14 AC 126 ms
55,636 KB
testcase_15 AC 124 ms
55,596 KB
testcase_16 AC 125 ms
55,356 KB
testcase_17 AC 123 ms
55,364 KB
testcase_18 AC 125 ms
55,800 KB
testcase_19 AC 125 ms
55,868 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