結果

問題 No.222 引き算と足し算
ユーザー uafr_csuafr_cs
提出日時 2015-06-16 23:29:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 1,000 ms
コード長 1,101 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 78,412 KB
実行使用メモリ 41,432 KB
最終ジャッジ日時 2024-04-27 17:42:10
合計ジャッジ時間 6,576 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
41,124 KB
testcase_01 AC 102 ms
41,184 KB
testcase_02 AC 101 ms
40,880 KB
testcase_03 AC 107 ms
40,968 KB
testcase_04 AC 107 ms
41,020 KB
testcase_05 AC 105 ms
41,248 KB
testcase_06 AC 106 ms
41,176 KB
testcase_07 AC 107 ms
40,916 KB
testcase_08 AC 101 ms
41,144 KB
testcase_09 AC 90 ms
39,576 KB
testcase_10 AC 101 ms
41,352 KB
testcase_11 AC 102 ms
41,128 KB
testcase_12 AC 103 ms
41,272 KB
testcase_13 AC 93 ms
39,992 KB
testcase_14 AC 112 ms
40,224 KB
testcase_15 AC 94 ms
40,252 KB
testcase_16 AC 103 ms
40,924 KB
testcase_17 AC 102 ms
41,164 KB
testcase_18 AC 103 ms
41,432 KB
testcase_19 AC 109 ms
41,152 KB
testcase_20 AC 92 ms
40,240 KB
testcase_21 AC 104 ms
41,292 KB
testcase_22 AC 102 ms
41,216 KB
testcase_23 AC 93 ms
40,148 KB
testcase_24 AC 104 ms
40,884 KB
testcase_25 AC 100 ms
41,408 KB
testcase_26 AC 109 ms
41,092 KB
testcase_27 AC 111 ms
41,180 KB
testcase_28 AC 111 ms
41,040 KB
testcase_29 AC 108 ms
41,316 KB
testcase_30 AC 100 ms
40,028 KB
testcase_31 AC 109 ms
41,088 KB
testcase_32 AC 115 ms
41,248 KB
testcase_33 AC 112 ms
41,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String input = sc.next();
		
		boolean is_minus = false;
		if(input.startsWith("-")){
			input = input.substring(1);
			is_minus = true;
		}else if(input.startsWith("+")){
			input = input.substring(1);
		}
		
		//System.out.println(input);
		
		final int plus_index = input.contains("+") ? input.indexOf("+") : Integer.MAX_VALUE;
		final int minus_index = input.contains("-") ? input.indexOf("-") : Integer.MAX_VALUE;
		
		if(plus_index < minus_index){
			final int fst = (is_minus ? -1 : 1) * Integer.parseInt(input.substring(0, input.indexOf("+")));
			final int snd = Integer.parseInt(input.substring(input.indexOf("+") + 1, input.length()));
			
			System.out.println(fst - snd);
		}else{
			final int fst = (is_minus ? -1 : 1) * Integer.parseInt(input.substring(0, input.indexOf("-")));
			final int snd = Integer.parseInt(input.substring(input.indexOf("-") + 1, input.length()));
			
			System.out.println(fst + snd);
		}
		
	}
	
}
0