結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-12-17 17:02:36 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 1,000 ms |
| コード長 | 1,397 bytes |
| コンパイル時間 | 2,628 ms |
| コンパイル使用メモリ | 77,160 KB |
| 実行使用メモリ | 37,108 KB |
| 最終ジャッジ日時 | 2024-07-04 01:24:38 |
| 合計ジャッジ時間 | 3,941 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
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);
}
}
htensai