結果

問題 No.222 引き算と足し算
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-16 04:26:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 935 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 74,784 KB
実行使用メモリ 56,192 KB
最終ジャッジ日時 2023-08-17 07:18:48
合計ジャッジ時間 7,702 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,860 KB
testcase_01 AC 117 ms
55,336 KB
testcase_02 AC 117 ms
55,844 KB
testcase_03 AC 117 ms
55,624 KB
testcase_04 AC 116 ms
55,960 KB
testcase_05 AC 118 ms
55,428 KB
testcase_06 AC 117 ms
55,676 KB
testcase_07 AC 117 ms
55,592 KB
testcase_08 AC 118 ms
55,864 KB
testcase_09 AC 120 ms
56,012 KB
testcase_10 AC 119 ms
55,640 KB
testcase_11 AC 121 ms
56,032 KB
testcase_12 AC 118 ms
55,716 KB
testcase_13 AC 115 ms
55,416 KB
testcase_14 AC 115 ms
56,020 KB
testcase_15 AC 116 ms
55,996 KB
testcase_16 AC 115 ms
55,592 KB
testcase_17 AC 118 ms
55,796 KB
testcase_18 AC 115 ms
55,700 KB
testcase_19 AC 120 ms
55,840 KB
testcase_20 AC 120 ms
55,968 KB
testcase_21 AC 117 ms
55,684 KB
testcase_22 AC 116 ms
55,672 KB
testcase_23 AC 117 ms
55,916 KB
testcase_24 AC 117 ms
56,044 KB
testcase_25 AC 116 ms
55,824 KB
testcase_26 AC 119 ms
56,192 KB
testcase_27 AC 118 ms
55,740 KB
testcase_28 AC 117 ms
55,788 KB
testcase_29 AC 117 ms
56,024 KB
testcase_30 AC 116 ms
55,988 KB
testcase_31 AC 119 ms
55,716 KB
testcase_32 AC 119 ms
55,456 KB
testcase_33 AC 118 ms
55,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String xopy = sc.next();
        int z = ind(xopy);
        int x = Integer.parseInt( xopy.substring(0,z) );
        int y = Integer.parseInt( xopy.substring(z+1) );
        String op = xopy.substring(z,z+1);
        int r =0;
        if( op.equals("+") ){
            r = x-y;
        }else{
            r = x+y;
        }
        System.out.println(r);
    }
    static int ind(String S){
        int n = S.indexOf("+");
        int m = S.indexOf("-");
        if(n==0){
            S=S.substring(1);
            n=S.indexOf("+")+1;
        }
        if(n<=0){
            n=Integer.MAX_VALUE;
        }
        if(m==0){
            S=S.substring(1);
            m=S.indexOf("-")+1;
        }
        if(m<=0){
            m=Integer.MAX_VALUE;
        }
        return Math.min(n,m);
    }
}

0