結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
54,160 KB
testcase_01 AC 122 ms
54,072 KB
testcase_02 AC 111 ms
52,828 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 112 ms
52,980 KB
testcase_10 AC 120 ms
54,124 KB
testcase_11 WA -
testcase_12 AC 120 ms
54,032 KB
testcase_13 AC 123 ms
54,148 KB
testcase_14 WA -
testcase_15 AC 121 ms
54,084 KB
testcase_16 AC 123 ms
53,836 KB
testcase_17 WA -
testcase_18 AC 125 ms
53,828 KB
testcase_19 AC 122 ms
54,144 KB
testcase_20 WA -
testcase_21 AC 120 ms
54,004 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 124 ms
53,872 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 123 ms
54,196 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 121 ms
54,228 KB
testcase_31 WA -
testcase_32 AC 121 ms
53,896 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;
		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