結果

問題 No.49 算数の宿題
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-18 23:11:43
言語 Java19
(openjdk 21)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 936 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 74,004 KB
実行使用メモリ 56,036 KB
最終ジャッジ日時 2023-08-24 17:25:23
合計ジャッジ時間 3,965 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,756 KB
testcase_01 AC 113 ms
55,848 KB
testcase_02 AC 112 ms
55,772 KB
testcase_03 AC 125 ms
56,036 KB
testcase_04 AC 113 ms
55,788 KB
testcase_05 AC 113 ms
55,876 KB
testcase_06 AC 113 ms
55,644 KB
testcase_07 AC 111 ms
55,884 KB
testcase_08 AC 113 ms
55,684 KB
testcase_09 AC 113 ms
55,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.regex.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        String s = koko.next();
        int n=0;
        String pn = "['*''+']+";
        Pattern pnum = Pattern.compile(pn);
        String[] num = pnum.split(s);
        int[] number = new int[num.length];
        String[] siki = new String[num.length-1];
        Matcher m = pnum.matcher(s);
        int si = 0;
        while(m.find()){
            siki[si++]=m.group(0);
        }
        for(int i=0; i<num.length; i++){
            number[i]=Integer.parseInt(num[i]);
        }
        int total=number[0];
        for(int i=0; i<siki.length; i++){
            if(siki[i].equals("+")){
                total=total*number[i+1];
            }else{
                total=total+number[i+1];
            }
        }
        System.out.println(total);
    }
}
0