結果

問題 No.222 引き算と足し算
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-14 15:37:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 1,000 ms
コード長 901 bytes
コンパイル時間 2,309 ms
コンパイル使用メモリ 81,468 KB
実行使用メモリ 56,096 KB
最終ジャッジ日時 2023-09-20 07:49:08
合計ジャッジ時間 8,432 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,576 KB
testcase_01 AC 122 ms
55,440 KB
testcase_02 AC 122 ms
55,492 KB
testcase_03 AC 122 ms
55,920 KB
testcase_04 AC 121 ms
55,768 KB
testcase_05 AC 122 ms
55,912 KB
testcase_06 AC 123 ms
55,800 KB
testcase_07 AC 125 ms
55,856 KB
testcase_08 AC 123 ms
55,812 KB
testcase_09 AC 123 ms
55,728 KB
testcase_10 AC 123 ms
55,896 KB
testcase_11 AC 126 ms
54,060 KB
testcase_12 AC 125 ms
55,660 KB
testcase_13 AC 126 ms
55,620 KB
testcase_14 AC 125 ms
55,804 KB
testcase_15 AC 123 ms
55,672 KB
testcase_16 AC 122 ms
55,888 KB
testcase_17 AC 125 ms
55,912 KB
testcase_18 AC 124 ms
55,912 KB
testcase_19 AC 126 ms
55,612 KB
testcase_20 AC 126 ms
55,884 KB
testcase_21 AC 128 ms
55,476 KB
testcase_22 AC 127 ms
55,796 KB
testcase_23 AC 125 ms
55,448 KB
testcase_24 AC 127 ms
56,072 KB
testcase_25 AC 126 ms
55,860 KB
testcase_26 AC 125 ms
55,740 KB
testcase_27 AC 127 ms
56,080 KB
testcase_28 AC 128 ms
55,856 KB
testcase_29 AC 124 ms
55,736 KB
testcase_30 AC 124 ms
56,096 KB
testcase_31 AC 124 ms
55,452 KB
testcase_32 AC 125 ms
55,844 KB
testcase_33 AC 125 ms
55,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String op = "";
    int p = 0;
    int t1 = 0;
    int t2 = 0;
    String st = "";
    for(int i = 0; i < s.length(); i++) {
      String str = String.valueOf(s.charAt(i));
      if(i == 0) {
        st += str;
      } else if(i < s.length() - 1) {
        if((str.equals("+")) || (str.equals("-"))) {
          if(p == 0) {
            t1 = Integer.parseInt(st);
            op = str;
            p++;
            st = "";
          } else {
            st += str;
          }
        } else {
          st += str;
        }
      } else {
        st += str;
        t2 = Integer.parseInt(st);
      }
    }
    int ans = 0;
    if(op.equals("-")) {
      ans = t1 + t2;
    } else {
      ans = t1 - t2;
    }
    System.out.println(ans);
  }
}
0