結果

問題 No.193 筒の数式
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-27 22:16:02
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,926 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 74,964 KB
実行使用メモリ 56,144 KB
最終ジャッジ日時 2023-09-18 13:56:37
合計ジャッジ時間 5,535 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,596 KB
testcase_01 AC 116 ms
55,852 KB
testcase_02 AC 114 ms
55,316 KB
testcase_03 AC 115 ms
55,728 KB
testcase_04 AC 115 ms
55,576 KB
testcase_05 AC 115 ms
55,560 KB
testcase_06 AC 114 ms
55,536 KB
testcase_07 AC 115 ms
55,576 KB
testcase_08 AC 118 ms
55,316 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 115 ms
55,724 KB
testcase_12 AC 115 ms
55,652 KB
testcase_13 AC 116 ms
55,308 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) throws Exception {
        Scanner koko = new Scanner(System.in);
        String s = koko.next();
        int n = s.length();
        String[] siki = new String[n];
        int count = 0;
        siki[count++]=s;
        for(int i=1; i<n; i++){
            if(s.charAt(i)!='+'&&s.charAt(i)!='-'){
                if(s.charAt(i-1)!='+'&&s.charAt(i-1)!='-'){
                    StringBuilder rest = new StringBuilder(s);
                    StringBuilder ku = new StringBuilder(s);
                    rest.delete(0, i);
                    String usiro = ku.substring(0, i);
                    rest.append(usiro);
                    siki[count++]=rest.toString();
                }
            }
        }
        int min = 0;
        for(int i=0; i<count; i++){
            min = Math.max(min, keisan(siki[i], 0, -1, '+', 0));
        }
        System.out.println(min);
    }
    static int keisan(String s, int moji, int hugo, char hu, int result){
        if(moji==s.length()-1){
            StringBuilder nu = new StringBuilder(s);
            nu.delete(0, hugo);
            int kazu = Integer.parseInt(nu.toString());
            if(hu=='+'){
                return result+kazu;
            }else{
                return result-kazu;
            }
        }else{
            if(s.charAt(moji)=='+'||s.charAt(moji)=='-'){
                StringBuilder nu = new StringBuilder(s);
                String num = nu.substring(hugo+1, moji);
                int number = Integer.parseInt(num);
                if(hu=='+'){
                    return keisan(s, moji+1, moji, s.charAt(moji), result+number);
                }else{
                    return keisan(s, moji+1, moji, s.charAt(moji), result-number);
                }
            }else{
                return keisan(s, moji+1, hugo, hu, result);
            }
        }
    }
}
0