結果

問題 No.222 引き算と足し算
ユーザー YamaKasa
提出日時 2018-09-01 19:14:33
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 796 bytes
コンパイル時間 3,278 ms
コンパイル使用メモリ 77,328 KB
実行使用メモリ 54,360 KB
最終ジャッジ日時 2024-09-19 17:28:08
合計ジャッジ時間 7,734 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 8 RE * 10
権限があれば一括ダウンロードができます

ソースコード

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