結果

問題 No.193 筒の数式
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-23 07:11:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,302 bytes
コンパイル時間 3,077 ms
コンパイル使用メモリ 76,300 KB
実行使用メモリ 56,484 KB
最終ジャッジ日時 2023-08-18 06:23:58
合計ジャッジ時間 5,957 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,692 KB
testcase_01 AC 118 ms
55,540 KB
testcase_02 AC 120 ms
55,480 KB
testcase_03 AC 123 ms
55,552 KB
testcase_04 AC 117 ms
55,760 KB
testcase_05 AC 117 ms
55,872 KB
testcase_06 AC 118 ms
55,564 KB
testcase_07 WA -
testcase_08 AC 117 ms
55,888 KB
testcase_09 AC 122 ms
53,988 KB
testcase_10 AC 117 ms
55,308 KB
testcase_11 AC 118 ms
55,648 KB
testcase_12 AC 120 ms
55,604 KB
testcase_13 AC 119 ms
55,480 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String [] arr = S.split("");
        int L = S.length();
        int max=0;
        for(int j=0; j<L; j++){
            String t = "";
            for(int i=0; i<L; i++){
                t+=arr[(i+j)%L];
            }
            if(t.charAt(0)>='0' && t.charAt(0)<='9' && t.charAt(L-1)>='0' && t.charAt(L-1)<='9'){
                int z = cal(t);
                max=Math.max(max,z);
            }
        }
        System.out.println(max);
    }
    static int cal(String S){
        String [] integer = S.split("[+-]");
        int a = S.indexOf("+");
        if(a==-1){a=10;}
        int b = S.indexOf("-");
        if(b==-1){b=10;}
        int m = Math.min(a,b);
        S=S.substring(m);
        String [] sign = S.split("[0-9]");
        int N = integer.length;
        int [] z = new int [N];
        for(int i=0; i<N; i++){
            z[i]=Integer.parseInt(integer[i]);
        }
        int r = z[0];
        for(int i=0; i<N-1; i++){
            if( "+".equals(sign[i]) ){
                r+=z[i+1];
            }else if( "-".equals(sign[i]) ){
                r-=z[i+1];
            }
        }
        return r;
    }
}
0