結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-12-28 14:33:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,350 bytes |
| コンパイル時間 | 1,810 ms |
| コンパイル使用メモリ | 74,952 KB |
| 実行使用メモリ | 54,724 KB |
| 最終ジャッジ日時 | 2024-10-03 04:50:34 |
| 合計ジャッジ時間 | 6,601 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 13 |
ソースコード
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);
}
}
tenten