結果

問題 No.222 引き算と足し算
ユーザー shinwisteriashinwisteria
提出日時 2017-04-02 14:54:20
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 802 bytes
コンパイル時間 3,591 ms
コンパイル使用メモリ 72,164 KB
実行使用メモリ 55,988 KB
最終ジャッジ日時 2023-09-22 07:37:44
合計ジャッジ時間 10,294 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,784 KB
testcase_01 AC 130 ms
55,560 KB
testcase_02 AC 129 ms
55,832 KB
testcase_03 AC 128 ms
55,788 KB
testcase_04 AC 128 ms
55,592 KB
testcase_05 AC 128 ms
55,876 KB
testcase_06 AC 124 ms
55,696 KB
testcase_07 AC 128 ms
55,804 KB
testcase_08 AC 126 ms
55,564 KB
testcase_09 AC 124 ms
55,776 KB
testcase_10 AC 129 ms
55,736 KB
testcase_11 AC 126 ms
53,976 KB
testcase_12 AC 127 ms
55,848 KB
testcase_13 AC 128 ms
55,468 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 128 ms
55,988 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 127 ms
55,784 KB
testcase_20 AC 131 ms
55,592 KB
testcase_21 AC 130 ms
55,616 KB
testcase_22 AC 131 ms
55,648 KB
testcase_23 AC 131 ms
55,860 KB
testcase_24 AC 135 ms
55,848 KB
testcase_25 AC 125 ms
55,772 KB
testcase_26 AC 133 ms
55,628 KB
testcase_27 AC 128 ms
55,824 KB
testcase_28 AC 128 ms
55,652 KB
testcase_29 AC 125 ms
55,576 KB
testcase_30 AC 130 ms
53,732 KB
testcase_31 AC 128 ms
55,820 KB
testcase_32 AC 128 ms
55,488 KB
testcase_33 AC 129 ms
55,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Tashihiki {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		StringBuilder str = new StringBuilder(s.nextLine());
		s.close();
		int sum = 0;
		int lp = str.lastIndexOf("+"),lm = str.lastIndexOf("-");
		int b = Integer.parseInt(str.substring(Math.max(lp, lm), str.length()));
		str.delete(Math.max(lm, lp), str.length());
		lp = str.lastIndexOf("+");
		lm = str.lastIndexOf("-");
		if(lp == -1&&lm == -1){
			sum = Integer.parseInt(str.toString()) - b;
		}else{
			int a = Integer.parseInt(str.substring(0, Math.max(lm, lp)));
			str.delete(0, Math.max(lp, lm));
			if(str.charAt(0) == '+'){
				sum = a-b;
			}else{
				sum = a+b;
			}
		}
		System.out.println(sum);
	}

}
0