結果

問題 No.222 引き算と足し算
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-06-05 23:01:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,878 bytes
コンパイル時間 3,624 ms
コンパイル使用メモリ 78,544 KB
実行使用メモリ 56,160 KB
最終ジャッジ日時 2024-04-27 17:23:54
合計ジャッジ時間 8,831 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
53,012 KB
testcase_01 AC 123 ms
54,060 KB
testcase_02 AC 125 ms
54,204 KB
testcase_03 AC 112 ms
52,900 KB
testcase_04 AC 125 ms
54,088 KB
testcase_05 WA -
testcase_06 AC 126 ms
54,084 KB
testcase_07 AC 124 ms
54,236 KB
testcase_08 WA -
testcase_09 AC 128 ms
53,832 KB
testcase_10 AC 127 ms
54,192 KB
testcase_11 WA -
testcase_12 AC 125 ms
54,272 KB
testcase_13 AC 112 ms
53,060 KB
testcase_14 WA -
testcase_15 AC 122 ms
55,948 KB
testcase_16 AC 124 ms
54,024 KB
testcase_17 WA -
testcase_18 AC 111 ms
52,936 KB
testcase_19 AC 125 ms
54,216 KB
testcase_20 WA -
testcase_21 AC 125 ms
53,928 KB
testcase_22 WA -
testcase_23 AC 120 ms
53,956 KB
testcase_24 AC 125 ms
54,004 KB
testcase_25 WA -
testcase_26 AC 124 ms
54,164 KB
testcase_27 AC 123 ms
54,120 KB
testcase_28 WA -
testcase_29 AC 123 ms
54,184 KB
testcase_30 AC 123 ms
54,212 KB
testcase_31 AC 125 ms
54,096 KB
testcase_32 AC 124 ms
54,132 KB
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No0222 {
    
    static final Scanner in = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        String s = in.next();
        int cnt = 0;
        for (int i=0; i<s.length(); i++) {
        	if (s.charAt(i) == '-' || s.charAt(i) == '+') {
        		cnt++;
        	}
        }

        if (cnt == 1) {
        	int ptr = 0;
        	int x = 0;
        	while (s.charAt(ptr) != '-' && s.charAt(ptr) != '+') {
        		x *= 10;
        		x += s.charAt(ptr) - '0';
        		ptr++;
        	}

        	boolean f = s.charAt(ptr) == '+';

        	int y = 0;
        	while (++ptr < s.length()) {
        		y *= 10;
        		y += s.charAt(ptr) - '0';
        	}

        	out.println(f?(x-y):(x+y));
        }

        if (cnt == 2 && '0' <= s.charAt(0) && s.charAt(0) <= '9') {
        	int ptr = 0;
        	int x = 0;
        	while (s.charAt(ptr) != '-' && s.charAt(ptr) != '+') {
        		x *= 10;
        		x += s.charAt(ptr) - '0';
        		ptr++;
        	}

        	boolean f = s.charAt(ptr) == '+';
        	boolean f2 = s.charAt(++ptr) == '+';

        	int y = 0;
        	while (++ptr < s.length()) {
        		y *= 10;
        		y += s.charAt(ptr) - '0';
        	}
        	if (!f2) y = -y;

        	out.println(f?(x-y):(x+y));
        }

        if (cnt == 2 && (s.charAt(0) == '+' || s.charAt(0) == '-')) {
        	int ptr = 0;
        	boolean f1 = s.charAt(++ptr) == '+';
        	int x = 0;
        	while (s.charAt(ptr) != '-' && s.charAt(ptr) != '+') {
        		x *= 10;
        		x += s.charAt(ptr) - '0';
        		ptr++;
        	}
        	if (!f1) x = -x;

        	boolean f = s.charAt(ptr) == '+';

        	int y = 0;
        	while (++ptr < s.length()) {
        		y *= 10;
        		y += s.charAt(ptr) - '0';
        	}

        	out.println(f?(x-y):(x+y));
        }

        if (cnt == 3) {
        	int ptr = 0;
	    	boolean f1 = s.charAt(++ptr) == '+';
	    	int x = 0;
	    	while (s.charAt(ptr) != '-' && s.charAt(ptr) != '+') {
	    		x *= 10;
	    		x += s.charAt(ptr) - '0';
	    		ptr++;
	    	}
	    	if (!f1) x = -x;

	    	boolean f = s.charAt(ptr) == '+';
	    	boolean f2 = s.charAt(++ptr) == '+';

	    	int y = 0;
	    	while (++ptr < s.length()) {
	    		y *= 10;
	    		y += s.charAt(ptr) - '0';
	    	}
	    	if (!f2) y = -y;

	    	out.println(f?(x-y):(x+y));	
        }
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        in.close();
        out.close();
    }

    static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}
0