結果
| 問題 | No.193 筒の数式 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-10-06 08:49:20 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 132 ms / 1,000 ms |
| コード長 | 1,498 bytes |
| 記録 | |
| コンパイル時間 | 2,155 ms |
| コンパイル使用メモリ | 77,168 KB |
| 実行使用メモリ | 41,404 KB |
| 最終ジャッジ日時 | 2024-07-20 00:35:18 |
| 合計ジャッジ時間 | 5,955 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] arr = sc.next().toCharArray();
int length = arr.length;
int max = Integer.MIN_VALUE;
for (int i = 0; i < length; i++) {
if (arr[i] == '+' || arr[i] == '-' || arr[(i - 1 + length) % length] == '+' || arr[(i - 1 + length) % length] == '-') {
continue;
}
int sum = 0;
boolean isPlus = true;
int tmp = 0;
for (int j = 0; j < length; j++) {
if (arr[(i + j) % length] == '+') {
if (isPlus) {
sum += tmp;
} else {
sum -= tmp;
}
isPlus = true;
tmp = 0;
} else if (arr[(i + j) % length] == '-') {
if (isPlus) {
sum += tmp;
} else {
sum -= tmp;
}
isPlus = false;
tmp = 0;
} else {
tmp *= 10;
tmp += arr[(i + j) % length] - '0';
}
}
if (isPlus) {
sum += tmp;
} else {
sum -= tmp;
}
max = Math.max(max, sum);
}
System.out.println(max);
}
}
tenten