結果

問題 No.222 引き算と足し算
ユーザー gu_21816943gu_21816943
提出日時 2017-06-28 22:35:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,178 bytes
コンパイル時間 2,919 ms
コンパイル使用メモリ 78,828 KB
実行使用メモリ 52,808 KB
最終ジャッジ日時 2024-04-15 04:10:06
合計ジャッジ時間 5,497 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 64 ms
50,668 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 63 ms
50,776 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 64 ms
50,680 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 67 ms
50,244 KB
testcase_22 AC 65 ms
50,612 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 64 ms
50,368 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 63 ms
50,548 KB
testcase_32 AC 65 ms
50,420 KB
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class Main {
	static PrintWriter out = new PrintWriter(System.out);
	static String str;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		br.close();

		int len = str.length();
		String result = "";
		boolean flag = false;
		int point = 0;

		for (int i = 0; i < len; i++) {
			if (str.charAt(i) == '+') {
				result += "-";
				if (flag) {
					flag = false;
					point = result.length();
				}
			} else if (str.charAt(i) == '-') {
				if (flag) {
					result += "+";
					flag = false;
					point = result.length();
				} else {

				}
			} else {
				result += str.substring(i, i + 1);
				if (point == 0) {
					flag = true;
				}
			}
		}
		if (str.indexOf("+") > 0) {
			System.out.println(
					Integer.parseInt(result.substring(0, point-1)) + Integer.parseInt(result.substring(point)));
		} else {
			System.out.println(
					Integer.parseInt(result.substring(0, point-1)) - Integer.parseInt(result.substring(point)));
		}
	}
}
0