結果

問題 No.222 引き算と足し算
ユーザー YamaKasaYamaKasa
提出日時 2018-09-01 19:14:33
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 796 bytes
コンパイル時間 2,424 ms
コンパイル使用メモリ 77,524 KB
実行使用メモリ 57,884 KB
最終ジャッジ日時 2023-10-19 21:26:09
合計ジャッジ時間 8,667 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,568 KB
testcase_01 AC 135 ms
57,572 KB
testcase_02 AC 133 ms
57,492 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 WA -
testcase_08 RE -
testcase_09 AC 133 ms
57,272 KB
testcase_10 AC 132 ms
57,700 KB
testcase_11 RE -
testcase_12 AC 147 ms
57,444 KB
testcase_13 AC 132 ms
57,152 KB
testcase_14 RE -
testcase_15 AC 134 ms
57,440 KB
testcase_16 AC 133 ms
57,444 KB
testcase_17 RE -
testcase_18 AC 131 ms
57,400 KB
testcase_19 AC 130 ms
57,596 KB
testcase_20 RE -
testcase_21 AC 133 ms
55,636 KB
testcase_22 RE -
testcase_23 WA -
testcase_24 AC 135 ms
57,396 KB
testcase_25 RE -
testcase_26 WA -
testcase_27 AC 132 ms
57,352 KB
testcase_28 RE -
testcase_29 WA -
testcase_30 AC 133 ms
57,188 KB
testcase_31 WA -
testcase_32 AC 134 ms
57,400 KB
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		scan.close();
		int l = s.length();
		int x = 0;
		int y = 0;
		int a = 0;

		if(s.charAt(0) == '-') {
			a = 1;
		}
		char c2 = '+';

		int b = 0;
		for(int i = a; i < l; i++) {
			if(s.charAt(i) == '-' || s.charAt(i) == '+') {
				x = Integer.parseInt(s.substring(a, i));
				if(s.charAt(i+1) == '+') {
					b = i;
					c2 = s.charAt(i);
					y = -Integer.parseInt(s.substring(b + 2, l));
					break;
				}
				b = i;
				c2 = s.charAt(i);
				y = Integer.parseInt(s.substring(b + 1, l));
				break;
			}
		}
		if(a == 1) {
			x = - x;
		}
		if(c2 == '+') {
			System.out.println(x - y);
		}else {
			System.out.println(x + y);
		}
	}
}
0