結果

問題 No.222 引き算と足し算
ユーザー shinwisteriashinwisteria
提出日時 2017-04-02 18:50:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 1,000 ms
コード長 815 bytes
コンパイル時間 3,604 ms
コンパイル使用メモリ 72,032 KB
実行使用メモリ 56,096 KB
最終ジャッジ日時 2023-09-22 07:42:17
合計ジャッジ時間 9,964 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,392 KB
testcase_01 AC 126 ms
55,856 KB
testcase_02 AC 125 ms
55,660 KB
testcase_03 AC 125 ms
55,596 KB
testcase_04 AC 125 ms
55,600 KB
testcase_05 AC 125 ms
55,852 KB
testcase_06 AC 127 ms
55,336 KB
testcase_07 AC 130 ms
55,672 KB
testcase_08 AC 128 ms
55,392 KB
testcase_09 AC 131 ms
55,656 KB
testcase_10 AC 127 ms
55,672 KB
testcase_11 AC 126 ms
55,744 KB
testcase_12 AC 127 ms
55,900 KB
testcase_13 AC 128 ms
56,096 KB
testcase_14 AC 131 ms
55,656 KB
testcase_15 AC 128 ms
55,700 KB
testcase_16 AC 128 ms
55,612 KB
testcase_17 AC 129 ms
56,048 KB
testcase_18 AC 128 ms
55,820 KB
testcase_19 AC 130 ms
55,740 KB
testcase_20 AC 129 ms
55,704 KB
testcase_21 AC 129 ms
55,744 KB
testcase_22 AC 128 ms
55,668 KB
testcase_23 AC 127 ms
55,596 KB
testcase_24 AC 128 ms
55,892 KB
testcase_25 AC 128 ms
55,540 KB
testcase_26 AC 129 ms
55,984 KB
testcase_27 AC 127 ms
55,944 KB
testcase_28 AC 126 ms
55,540 KB
testcase_29 AC 130 ms
55,812 KB
testcase_30 AC 128 ms
55,716 KB
testcase_31 AC 127 ms
55,696 KB
testcase_32 AC 128 ms
55,984 KB
testcase_33 AC 129 ms
55,912 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 <= 0 && lm <= 0){  //要修正
			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