結果

問題 No.193 筒の数式
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-27 22:39:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 1,000 ms
コード長 1,936 bytes
コンパイル時間 4,034 ms
コンパイル使用メモリ 74,836 KB
実行使用メモリ 55,792 KB
最終ジャッジ日時 2023-09-18 13:56:59
合計ジャッジ時間 5,733 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,616 KB
testcase_01 AC 126 ms
55,432 KB
testcase_02 AC 126 ms
55,356 KB
testcase_03 AC 127 ms
53,596 KB
testcase_04 AC 126 ms
55,476 KB
testcase_05 AC 125 ms
55,240 KB
testcase_06 AC 128 ms
55,772 KB
testcase_07 AC 125 ms
55,508 KB
testcase_08 AC 127 ms
55,232 KB
testcase_09 AC 123 ms
55,500 KB
testcase_10 AC 126 ms
55,508 KB
testcase_11 AC 125 ms
55,772 KB
testcase_12 AC 124 ms
55,436 KB
testcase_13 AC 128 ms
55,420 KB
testcase_14 AC 129 ms
55,792 KB
testcase_15 AC 125 ms
55,288 KB
testcase_16 AC 125 ms
55,532 KB
testcase_17 AC 125 ms
53,628 KB
testcase_18 AC 125 ms
55,492 KB
権限があれば一括ダウンロードができます

ソースコード

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 = -99999999;
        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+1);
            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