結果

問題 No.49 算数の宿題
ユーザー rn4rurn4ru
提出日時 2016-04-14 07:13:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 671 bytes
コンパイル時間 2,642 ms
コンパイル使用メモリ 71,176 KB
実行使用メモリ 56,028 KB
最終ジャッジ日時 2023-08-24 17:31:40
合計ジャッジ時間 5,453 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,816 KB
testcase_01 AC 118 ms
55,636 KB
testcase_02 AC 117 ms
55,760 KB
testcase_03 AC 118 ms
55,852 KB
testcase_04 AC 116 ms
55,760 KB
testcase_05 AC 116 ms
55,732 KB
testcase_06 AC 116 ms
56,028 KB
testcase_07 AC 117 ms
55,696 KB
testcase_08 AC 117 ms
55,388 KB
testcase_09 AC 115 ms
55,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		char[] S = scanner.next().toCharArray();
		int ans = 0, temp = 0, op = 0;
		for (int i = 0; i < S.length; i++) {
			if (S[i] == '+') {
				if (op == 1) {
					ans *= temp;
				} else {
					ans += temp;
				}
				temp = 0;
				op = 1;
			} else if (S[i] == '*') {
				if (op == 1) {
					ans *= temp;
				} else {
					ans += temp;
				}
				temp = 0;
				op = 0;
			} else {
				temp *= 10;
				temp += S[i] - '0';
			}
		}
		if (op == 1) {
			ans *= temp;
		} else {
			ans += temp;
		}
		temp = 0;

		System.out.println(ans);
	}

}
0