結果

問題 No.222 引き算と足し算
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-14 15:37:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 109 ms / 1,000 ms
コード長 901 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 77,532 KB
実行使用メモリ 41,204 KB
最終ジャッジ日時 2024-07-06 03:42:23
合計ジャッジ時間 6,842 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
40,852 KB
testcase_01 AC 101 ms
40,936 KB
testcase_02 AC 98 ms
41,112 KB
testcase_03 AC 103 ms
41,020 KB
testcase_04 AC 92 ms
40,012 KB
testcase_05 AC 90 ms
39,924 KB
testcase_06 AC 99 ms
40,744 KB
testcase_07 AC 87 ms
39,928 KB
testcase_08 AC 95 ms
40,992 KB
testcase_09 AC 98 ms
40,764 KB
testcase_10 AC 93 ms
41,052 KB
testcase_11 AC 100 ms
40,868 KB
testcase_12 AC 102 ms
40,744 KB
testcase_13 AC 99 ms
41,188 KB
testcase_14 AC 109 ms
40,772 KB
testcase_15 AC 88 ms
39,612 KB
testcase_16 AC 103 ms
40,860 KB
testcase_17 AC 97 ms
41,048 KB
testcase_18 AC 101 ms
41,072 KB
testcase_19 AC 102 ms
41,048 KB
testcase_20 AC 101 ms
41,028 KB
testcase_21 AC 92 ms
40,296 KB
testcase_22 AC 100 ms
40,924 KB
testcase_23 AC 102 ms
41,188 KB
testcase_24 AC 98 ms
40,908 KB
testcase_25 AC 101 ms
41,204 KB
testcase_26 AC 91 ms
40,376 KB
testcase_27 AC 91 ms
39,736 KB
testcase_28 AC 105 ms
40,752 KB
testcase_29 AC 101 ms
40,880 KB
testcase_30 AC 92 ms
40,192 KB
testcase_31 AC 102 ms
41,056 KB
testcase_32 AC 100 ms
41,156 KB
testcase_33 AC 101 ms
40,868 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