結果
問題 | No.222 引き算と足し算 |
ユーザー | tenten |
提出日時 | 2020-12-28 14:33:08 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,350 bytes |
コンパイル時間 | 2,610 ms |
コンパイル使用メモリ | 75,112 KB |
実行使用メモリ | 56,180 KB |
最終ジャッジ日時 | 2024-04-14 07:41:53 |
合計ジャッジ時間 | 8,046 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 132 ms
53,844 KB |
testcase_01 | AC | 123 ms
54,068 KB |
testcase_02 | AC | 127 ms
54,072 KB |
testcase_03 | AC | 125 ms
53,896 KB |
testcase_04 | AC | 125 ms
54,356 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 126 ms
54,304 KB |
testcase_10 | AC | 127 ms
54,164 KB |
testcase_11 | WA | - |
testcase_12 | AC | 127 ms
54,144 KB |
testcase_13 | AC | 124 ms
53,904 KB |
testcase_14 | WA | - |
testcase_15 | AC | 125 ms
53,904 KB |
testcase_16 | AC | 126 ms
54,260 KB |
testcase_17 | WA | - |
testcase_18 | AC | 128 ms
54,340 KB |
testcase_19 | AC | 128 ms
53,880 KB |
testcase_20 | WA | - |
testcase_21 | AC | 126 ms
54,396 KB |
testcase_22 | WA | - |
testcase_23 | AC | 126 ms
54,200 KB |
testcase_24 | AC | 125 ms
54,080 KB |
testcase_25 | WA | - |
testcase_26 | AC | 125 ms
54,016 KB |
testcase_27 | AC | 128 ms
53,988 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 126 ms
54,012 KB |
testcase_31 | AC | 126 ms
54,120 KB |
testcase_32 | AC | 126 ms
54,092 KB |
testcase_33 | WA | - |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); boolean start = true; boolean isPlus = true; int num1 = 0; int num2 = 0; for (char c : sc.next().toCharArray()) { if (c == '+') { if (isPlus) { num1 += num2; num2 = 0; } else { num1 -= num2; num2 = 0; } isPlus = false; start = true; } else if (c == '-') { if (start) { isPlus ^= true; start = false; } else { if (isPlus) { num1 += num2; num2 = 0; } else { num1 -= num2; num2 = 0; } isPlus = true; start = true; } } else { num2 *= 10; num2 += c - '0'; start = false; } } if (isPlus) { num1 += num2; } else { num1 -= num2; } System.out.println(num1); } }