結果

問題 No.222 引き算と足し算
ユーザー YamaKasaYamaKasa
提出日時 2018-09-01 19:32:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 1,000 ms
コード長 989 bytes
コンパイル時間 2,500 ms
コンパイル使用メモリ 78,064 KB
実行使用メモリ 57,588 KB
最終ジャッジ日時 2023-10-19 21:50:40
合計ジャッジ時間 7,851 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,540 KB
testcase_01 AC 130 ms
57,436 KB
testcase_02 AC 131 ms
57,160 KB
testcase_03 AC 130 ms
57,136 KB
testcase_04 AC 132 ms
57,136 KB
testcase_05 AC 131 ms
57,364 KB
testcase_06 AC 129 ms
57,180 KB
testcase_07 AC 130 ms
57,284 KB
testcase_08 AC 130 ms
57,392 KB
testcase_09 AC 129 ms
57,192 KB
testcase_10 AC 128 ms
57,436 KB
testcase_11 AC 132 ms
57,168 KB
testcase_12 AC 127 ms
57,588 KB
testcase_13 AC 127 ms
57,384 KB
testcase_14 AC 130 ms
57,540 KB
testcase_15 AC 128 ms
57,116 KB
testcase_16 AC 130 ms
55,520 KB
testcase_17 AC 130 ms
57,332 KB
testcase_18 AC 130 ms
57,416 KB
testcase_19 AC 130 ms
56,952 KB
testcase_20 AC 127 ms
57,400 KB
testcase_21 AC 127 ms
57,176 KB
testcase_22 AC 127 ms
57,368 KB
testcase_23 AC 129 ms
57,164 KB
testcase_24 AC 127 ms
57,300 KB
testcase_25 AC 129 ms
57,132 KB
testcase_26 AC 127 ms
57,404 KB
testcase_27 AC 128 ms
55,700 KB
testcase_28 AC 128 ms
57,436 KB
testcase_29 AC 126 ms
57,320 KB
testcase_30 AC 127 ms
56,936 KB
testcase_31 AC 128 ms
57,108 KB
testcase_32 AC 125 ms
57,392 KB
testcase_33 AC 128 ms
57,140 KB
権限があれば一括ダウンロードができます

ソースコード

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;
		}else 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(s.charAt(0) == '-') {
			x = - x;
		}
		if(c2 == '+') {
			System.out.println(x - y);
		}else {
			System.out.println(x + y);
		}
	}
}
0