結果

問題 No.222 引き算と足し算
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-16 19:57:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 120 ms / 1,000 ms
コード長 691 bytes
コンパイル時間 3,607 ms
コンパイル使用メモリ 75,244 KB
実行使用メモリ 54,148 KB
最終ジャッジ日時 2024-04-27 17:53:50
合計ジャッジ時間 7,303 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
52,516 KB
testcase_01 AC 97 ms
52,520 KB
testcase_02 AC 117 ms
53,464 KB
testcase_03 AC 105 ms
53,660 KB
testcase_04 AC 105 ms
54,000 KB
testcase_05 AC 105 ms
53,808 KB
testcase_06 AC 92 ms
52,444 KB
testcase_07 AC 108 ms
53,676 KB
testcase_08 AC 106 ms
54,000 KB
testcase_09 AC 95 ms
52,824 KB
testcase_10 AC 108 ms
54,108 KB
testcase_11 AC 112 ms
54,044 KB
testcase_12 AC 108 ms
54,148 KB
testcase_13 AC 94 ms
52,528 KB
testcase_14 AC 107 ms
54,008 KB
testcase_15 AC 105 ms
52,984 KB
testcase_16 AC 105 ms
53,880 KB
testcase_17 AC 97 ms
52,952 KB
testcase_18 AC 114 ms
53,768 KB
testcase_19 AC 106 ms
53,612 KB
testcase_20 AC 107 ms
54,048 KB
testcase_21 AC 92 ms
52,460 KB
testcase_22 AC 98 ms
52,788 KB
testcase_23 AC 111 ms
53,872 KB
testcase_24 AC 119 ms
54,072 KB
testcase_25 AC 120 ms
53,732 KB
testcase_26 AC 102 ms
53,336 KB
testcase_27 AC 99 ms
52,368 KB
testcase_28 AC 97 ms
52,712 KB
testcase_29 AC 110 ms
54,032 KB
testcase_30 AC 114 ms
53,920 KB
testcase_31 AC 112 ms
53,940 KB
testcase_32 AC 106 ms
53,744 KB
testcase_33 AC 106 ms
53,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise89{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    String s = sc.next();

    char[] sArray = s.toCharArray();
    char op = 'a';
    boolean num = false;
    int index = 0;

    for(int i = 0; i < sArray.length; i++){
      if(num && !Character.isLetterOrDigit(sArray[i])){
        op = sArray[i];
        index = i;
      }

      num = Character.isLetterOrDigit(sArray[i]);
    }
    int firstNum = Integer.parseInt(s.substring(0, index));
    int secondNum = Integer.parseInt(s.substring(index + 1, s.length()));

    System.out.println((op == '+') ? firstNum - secondNum : firstNum + secondNum);
  }
}
0