結果

問題 No.49 算数の宿題
ユーザー Grenache
提出日時 2015-11-03 19:25:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 995 bytes
コンパイル時間 3,128 ms
コンパイル使用メモリ 74,848 KB
実行使用メモリ 41,208 KB
最終ジャッジ日時 2024-12-23 01:46:46
合計ジャッジ時間 4,946 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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