結果

問題 No.222 引き算と足し算
ユーザー k_kadorak_kadora
提出日時 2015-06-19 21:33:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 1,101 bytes
コンパイル時間 3,552 ms
コンパイル使用メモリ 78,104 KB
実行使用メモリ 54,272 KB
最終ジャッジ日時 2024-04-27 17:42:53
合計ジャッジ時間 8,649 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
52,756 KB
testcase_01 AC 124 ms
53,952 KB
testcase_02 AC 119 ms
54,064 KB
testcase_03 AC 122 ms
54,180 KB
testcase_04 AC 122 ms
54,272 KB
testcase_05 AC 120 ms
53,736 KB
testcase_06 AC 120 ms
53,816 KB
testcase_07 AC 123 ms
53,872 KB
testcase_08 AC 122 ms
53,864 KB
testcase_09 AC 127 ms
54,016 KB
testcase_10 AC 121 ms
54,052 KB
testcase_11 AC 108 ms
52,976 KB
testcase_12 AC 124 ms
54,048 KB
testcase_13 AC 120 ms
54,176 KB
testcase_14 AC 123 ms
54,124 KB
testcase_15 AC 109 ms
52,624 KB
testcase_16 AC 122 ms
53,988 KB
testcase_17 AC 120 ms
54,124 KB
testcase_18 AC 120 ms
54,264 KB
testcase_19 AC 123 ms
53,836 KB
testcase_20 AC 121 ms
54,080 KB
testcase_21 AC 122 ms
54,144 KB
testcase_22 AC 109 ms
52,640 KB
testcase_23 AC 122 ms
54,028 KB
testcase_24 AC 123 ms
54,000 KB
testcase_25 AC 119 ms
53,896 KB
testcase_26 AC 107 ms
52,744 KB
testcase_27 AC 120 ms
53,880 KB
testcase_28 AC 122 ms
54,116 KB
testcase_29 AC 122 ms
54,212 KB
testcase_30 AC 123 ms
53,976 KB
testcase_31 AC 122 ms
54,004 KB
testcase_32 AC 105 ms
52,816 KB
testcase_33 AC 121 ms
54,044 KB
権限があれば一括ダウンロードができます

ソースコード

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{
				if(s.charAt(i) == '+')i++;
				y = value(s,i);
			}
		}else{
			if(s.charAt(i) == '+')i++;
			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{
				if(s.charAt(i) == '+')i++;
				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