結果

問題 No.193 筒の数式
ユーザー htensaihtensai
提出日時 2019-12-17 17:02:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 43 ms / 1,000 ms
コード長 1,397 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 74,100 KB
実行使用メモリ 49,724 KB
最終ジャッジ日時 2023-09-17 03:41:37
合計ジャッジ時間 3,707 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,260 KB
testcase_01 AC 42 ms
49,144 KB
testcase_02 AC 42 ms
49,424 KB
testcase_03 AC 42 ms
49,724 KB
testcase_04 AC 42 ms
49,316 KB
testcase_05 AC 42 ms
49,196 KB
testcase_06 AC 41 ms
49,372 KB
testcase_07 AC 42 ms
49,160 KB
testcase_08 AC 42 ms
49,144 KB
testcase_09 AC 42 ms
49,356 KB
testcase_10 AC 43 ms
49,276 KB
testcase_11 AC 43 ms
49,316 KB
testcase_12 AC 43 ms
49,536 KB
testcase_13 AC 43 ms
49,448 KB
testcase_14 AC 43 ms
49,724 KB
testcase_15 AC 42 ms
49,516 KB
testcase_16 AC 42 ms
49,372 KB
testcase_17 AC 42 ms
49,384 KB
testcase_18 AC 42 ms
49,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[] arr = br.readLine().toCharArray();
        int length = arr.length;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < length; i++) {
            char[] tmp = new char[length];
            for (int j = 0; j < length; j++) {
                tmp[j] = arr[(i + j) % length];
            }
            if (tmp[0] == '+' || tmp[0] == '-' || tmp[length - 1] == '+' || tmp[length - 1] == '-') {
                continue;
            }
            char op = '+';
            int ans = 0;
            int cur = 0;
            for (int j = 0; j < length; j++) {
                if (tmp[j] == '+' || tmp[j] == '-') {
                    if (op == '+') {
                        ans += cur;
                    } else {
                        ans -= cur;
                    }
                    op = tmp[j];
                    cur = 0;
                } else {
                    cur *= 10;
                    cur += tmp[j] - '0';
                }
            }
            if (op == '+') {
                ans += cur;
            } else {
                ans -= cur;
            }
            max = Math.max(ans, max);
        }
        System.out.println(max);
    }
}
0