結果

問題 No.222 引き算と足し算
ユーザー uafr_cs
提出日時 2015-06-16 23:29:45
言語 Java
(openjdk 23)
結果
AC  
実行時間 123 ms / 1,000 ms
コード長 1,101 bytes
コンパイル時間 2,484 ms
コンパイル使用メモリ 78,080 KB
実行使用メモリ 41,652 KB
最終ジャッジ日時 2024-11-15 21:55:44
合計ジャッジ時間 7,121 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

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