結果

問題 No.49 算数の宿題
ユーザー htensai
提出日時 2019-12-06 23:20:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 145 ms / 5,000 ms
コード長 614 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 75,156 KB
実行使用メモリ 41,440 KB
最終ジャッジ日時 2024-12-23 02:05:18
合計ジャッジ時間 4,228 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int tmp = 0;
		int ans = 0;
		char op = '*';
		for (char c : arr) {
		    if (c == '+' || c == '*') {
		        if (op == '+') {
		            ans *= tmp;
		        } else {
		            ans += tmp;
		        }
		        op = c;
		        tmp = 0;
		    } else {
		        tmp = tmp * 10 + (c - '0');
		    }
		}
        if (op == '+') {
            ans *= tmp;
        } else {
            ans += tmp;
        }
		System.out.println(ans);
   }
}

0