結果

問題 No.222 引き算と足し算
ユーザー htensaihtensai
提出日時 2019-11-24 11:57:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 1,000 ms
コード長 795 bytes
コンパイル時間 2,254 ms
コンパイル使用メモリ 75,028 KB
実行使用メモリ 41,568 KB
最終ジャッジ日時 2024-04-20 08:54:30
合計ジャッジ時間 7,831 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
40,968 KB
testcase_01 AC 112 ms
41,036 KB
testcase_02 AC 128 ms
41,424 KB
testcase_03 AC 128 ms
41,396 KB
testcase_04 AC 127 ms
40,748 KB
testcase_05 AC 113 ms
40,096 KB
testcase_06 AC 129 ms
41,460 KB
testcase_07 AC 127 ms
41,164 KB
testcase_08 AC 127 ms
41,532 KB
testcase_09 AC 127 ms
41,312 KB
testcase_10 AC 128 ms
41,376 KB
testcase_11 AC 124 ms
41,408 KB
testcase_12 AC 127 ms
41,120 KB
testcase_13 AC 127 ms
41,568 KB
testcase_14 AC 114 ms
39,888 KB
testcase_15 AC 125 ms
41,120 KB
testcase_16 AC 126 ms
41,088 KB
testcase_17 AC 129 ms
41,020 KB
testcase_18 AC 127 ms
41,120 KB
testcase_19 AC 128 ms
41,312 KB
testcase_20 AC 128 ms
41,196 KB
testcase_21 AC 132 ms
41,240 KB
testcase_22 AC 129 ms
41,164 KB
testcase_23 AC 127 ms
41,056 KB
testcase_24 AC 124 ms
40,872 KB
testcase_25 AC 128 ms
41,332 KB
testcase_26 AC 123 ms
40,936 KB
testcase_27 AC 126 ms
41,008 KB
testcase_28 AC 126 ms
41,112 KB
testcase_29 AC 124 ms
41,228 KB
testcase_30 AC 108 ms
41,376 KB
testcase_31 AC 125 ms
41,364 KB
testcase_32 AC 126 ms
41,468 KB
testcase_33 AC 127 ms
41,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
   }
}

0