結果

問題 No.49 算数の宿題
ユーザー mosmos_21mosmos_21
提出日時 2017-06-18 21:20:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 546 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 71,692 KB
実行使用メモリ 56,140 KB
最終ジャッジ日時 2023-08-24 17:37:26
合計ジャッジ時間 4,027 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,080 KB
testcase_01 AC 122 ms
55,648 KB
testcase_02 AC 123 ms
55,816 KB
testcase_03 AC 125 ms
55,768 KB
testcase_04 AC 123 ms
55,904 KB
testcase_05 AC 122 ms
55,836 KB
testcase_06 AC 123 ms
56,140 KB
testcase_07 AC 124 ms
56,032 KB
testcase_08 AC 123 ms
55,516 KB
testcase_09 AC 122 ms
55,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Main {
    static Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        String[] s = in.nextLine().replaceAll("(\\+|\\*)", "_$1_").split("_");
        int sum = Integer.parseInt(s[0]);
        for(int i = 1; i < s.length; i += 2){
            if(s[i].equals("+")){
                sum *= Integer.parseInt(s[i + 1]);
            }else if(s[i].equals("*")){
                sum += Integer.parseInt(s[i + 1]);
            }
        }
        System.out.println(sum);
    }
}
0