結果

問題 No.49 算数の宿題
ユーザー GrenacheGrenache
提出日時 2015-11-03 19:25:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 117 ms / 5,000 ms
コード長 995 bytes
コンパイル時間 3,058 ms
コンパイル使用メモリ 72,516 KB
実行使用メモリ 56,192 KB
最終ジャッジ日時 2023-08-24 17:27:08
合計ジャッジ時間 4,915 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,956 KB
testcase_01 AC 117 ms
56,192 KB
testcase_02 AC 113 ms
55,864 KB
testcase_03 AC 114 ms
56,032 KB
testcase_04 AC 116 ms
55,836 KB
testcase_05 AC 115 ms
55,380 KB
testcase_06 AC 114 ms
55,764 KB
testcase_07 AC 115 ms
53,756 KB
testcase_08 AC 116 ms
55,332 KB
testcase_09 AC 116 ms
55,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder49 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        int ret = 0;
        boolean p = true;
        for (int i = 0; i < s.length(); ) {
        	int plus = s.indexOf('*', i);
        	if (plus == -1) {
        		plus = s.length();
        	}
        	int mul = s.indexOf('+', i);
        	if (mul == -1) {
        		mul = s.length();
        	}
        	int next;
        	if (plus < mul) {
        		next = plus;
        	} else {
        		next = mul;
        	}
        	
        	int tmp = Integer.parseInt(s.substring(i, next));
        	
        	if (p) {
        		ret += tmp;
        	} else {
        		ret *= tmp;
        	}
        	
        	if (next == plus) {
        		p = true;
        	} else {
        		p = false;
        	}
        	
        	i = next + 1;
        }
        
        System.out.println(ret);

        sc.close();
    }
}
0