結果

問題 No.222 引き算と足し算
ユーザー k_kadorak_kadora
提出日時 2015-06-19 21:26:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,038 bytes
コンパイル時間 3,621 ms
コンパイル使用メモリ 77,276 KB
実行使用メモリ 54,548 KB
最終ジャッジ日時 2024-04-27 17:42:36
合計ジャッジ時間 8,919 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
54,084 KB
testcase_01 AC 139 ms
54,180 KB
testcase_02 AC 129 ms
54,064 KB
testcase_03 AC 128 ms
54,004 KB
testcase_04 AC 125 ms
53,992 KB
testcase_05 WA -
testcase_06 AC 126 ms
54,304 KB
testcase_07 AC 126 ms
54,132 KB
testcase_08 WA -
testcase_09 AC 124 ms
54,380 KB
testcase_10 AC 121 ms
53,824 KB
testcase_11 WA -
testcase_12 AC 124 ms
53,808 KB
testcase_13 AC 125 ms
54,096 KB
testcase_14 WA -
testcase_15 AC 121 ms
53,932 KB
testcase_16 AC 121 ms
54,076 KB
testcase_17 WA -
testcase_18 AC 130 ms
54,132 KB
testcase_19 AC 139 ms
54,044 KB
testcase_20 WA -
testcase_21 AC 138 ms
53,908 KB
testcase_22 AC 127 ms
54,044 KB
testcase_23 AC 126 ms
54,164 KB
testcase_24 AC 128 ms
54,100 KB
testcase_25 WA -
testcase_26 AC 123 ms
54,088 KB
testcase_27 AC 124 ms
54,160 KB
testcase_28 WA -
testcase_29 AC 121 ms
53,996 KB
testcase_30 AC 125 ms
53,944 KB
testcase_31 AC 122 ms
53,804 KB
testcase_32 AC 123 ms
53,944 KB
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Yuki222{
	public static void main(String[] arg){
		Scanner sc = new Scanner(System.in);
		int x,y,res=0,i=0;
		String s;
		boolean plus=false;
		s = sc.next();
		if(s.charAt(i) == '-'){
			i++;
			x = (-1)*value(s,i);
			while('0'<= s.charAt(i) && s.charAt(i) <= '9')i++;
			if(s.charAt(i) == '+')plus = true;
			i++;
			if(s.charAt(i) == '-'){
				y = (-1)*value(s,i+1);
			}else{
				y = value(s,i);
			}
		}else{
			x = value(s,i);
			while('0'<= s.charAt(i) && s.charAt(i) <= '9')i++;
			if(s.charAt(i) == '+')plus = true;
			i++;
			if(s.charAt(i) == '-'){
				y = (-1)*value(s,i+1);
			}else{
				y = value(s,i);
			}
		}
		if(plus){
			res = x - y;
		}else{
			res = x + y;
		}
		System.out.println(res);
	}
	public static int value(String s,int i){
		int temp = 0;
		if(s.charAt(i) == '+')i++;
		while(i<s.length()){
			if('0'<= s.charAt(i) && s.charAt(i) <= '9'){
				temp = temp * 10 + Character.getNumericValue(s.charAt(i));
			}else{
				return temp;
			}
			i++;
		}
		return temp;
	}
}
0