結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,184 KB
testcase_01 AC 132 ms
57,188 KB
testcase_02 AC 133 ms
57,192 KB
testcase_03 AC 132 ms
57,280 KB
testcase_04 AC 131 ms
57,444 KB
testcase_05 RE -
testcase_06 AC 134 ms
57,200 KB
testcase_07 AC 130 ms
57,400 KB
testcase_08 RE -
testcase_09 AC 134 ms
57,596 KB
testcase_10 AC 132 ms
57,440 KB
testcase_11 RE -
testcase_12 AC 134 ms
57,128 KB
testcase_13 AC 134 ms
57,476 KB
testcase_14 RE -
testcase_15 AC 133 ms
57,648 KB
testcase_16 AC 136 ms
57,148 KB
testcase_17 RE -
testcase_18 AC 134 ms
57,272 KB
testcase_19 AC 133 ms
57,160 KB
testcase_20 RE -
testcase_21 AC 131 ms
57,188 KB
testcase_22 RE -
testcase_23 AC 133 ms
57,448 KB
testcase_24 AC 136 ms
57,624 KB
testcase_25 RE -
testcase_26 AC 132 ms
57,452 KB
testcase_27 AC 131 ms
57,208 KB
testcase_28 RE -
testcase_29 AC 130 ms
57,400 KB
testcase_30 AC 134 ms
57,188 KB
testcase_31 AC 133 ms
57,472 KB
testcase_32 AC 134 ms
57,552 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;
				}else 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