結果
問題 | No.222 引き算と足し算 |
ユーザー |
![]() |
提出日時 | 2019-11-24 11:57:08 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 124 ms / 1,000 ms |
コード長 | 795 bytes |
コンパイル時間 | 2,600 ms |
コンパイル使用メモリ | 75,128 KB |
実行使用メモリ | 54,132 KB |
最終ジャッジ日時 | 2024-10-12 04:17:26 |
合計ジャッジ時間 | 7,447 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); char[] arr = sc.next().toCharArray(); StringBuilder[] sbs = new StringBuilder[2]; boolean isPlus = true; int idx = 0; for (int i = 0; i < 2; i++) { sbs[i] = new StringBuilder(); while (idx < arr.length) { char c = arr[idx]; if (sbs[i].length() > 0 && (c == '+' || c == '-')) { isPlus = c == '-'; idx++; break; } sbs[i].append(c); idx++; } } int a = Integer.parseInt(sbs[0].toString()); int b = Integer.parseInt(sbs[1].toString()); int ans; if (isPlus) { ans = a + b; } else { ans = a - b; } System.out.println(ans); } }