結果

問題 No.49 算数の宿題
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-14 13:58:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,201 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 75,984 KB
実行使用メモリ 58,568 KB
最終ジャッジ日時 2023-08-24 17:43:49
合計ジャッジ時間 3,979 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 123 ms
55,696 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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