結果
問題 |
No.708 (+ー)の式
|
ユーザー |
![]() |
提出日時 | 2020-01-18 20:22:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 1,235 bytes |
コンパイル時間 | 2,427 ms |
コンパイル使用メモリ | 75,760 KB |
実行使用メモリ | 37,132 KB |
最終ジャッジ日時 | 2024-06-28 02:41:18 |
合計ジャッジ時間 | 3,807 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
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(); ArrayDeque<Integer> deqInt = new ArrayDeque<>(); ArrayDeque<Boolean> deqBool = new ArrayDeque<>(); int base = 0; boolean isPlus = true; for (char c : arr) { if (c == '+') { isPlus = true; } else if (c == '-') { isPlus = false; } else if (c == '(') { deqInt.push(base); deqBool.push(isPlus); base = 0; isPlus = true; } else if (c == ')') { int x = deqInt.pop(); isPlus = deqBool.pop(); if (isPlus) { base = x + base; } else { base = x - base; } } else { if (isPlus) { base += c - '0'; } else { base -= c - '0'; } } } System.out.println(base); } }