結果

問題 No.49 算数の宿題
ユーザー bambambambam
提出日時 2019-08-22 15:37:30
言語 Java19
(openjdk 21)
結果
AC  
実行時間 156 ms / 5,000 ms
コード長 1,004 bytes
コンパイル時間 4,371 ms
コンパイル使用メモリ 81,412 KB
実行使用メモリ 57,020 KB
最終ジャッジ日時 2023-08-24 17:43:25
合計ジャッジ時間 4,628 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
56,800 KB
testcase_01 AC 153 ms
56,700 KB
testcase_02 AC 152 ms
57,004 KB
testcase_03 AC 151 ms
56,856 KB
testcase_04 AC 152 ms
56,972 KB
testcase_05 AC 156 ms
56,648 KB
testcase_06 AC 152 ms
56,768 KB
testcase_07 AC 155 ms
57,020 KB
testcase_08 AC 154 ms
56,784 KB
testcase_09 AC 151 ms
56,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static boolean memo[];
	static int ans, min;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char[] s = sc.next().toCharArray();
		String a = "", b = "";
		int sum = 0;
		int idx = 0;
		for (int i = 0; i < s.length; i++) {
			if (s[i] == '+') {
				i++;
				if (!a.equals("")) {
					sum += Integer.parseInt(a);
				}
				a = "";
				for (; i < s.length; i++) {
					if (s[i] != '*' && s[i] != '+') {
						a += s[i];
					} else {
						i--;
						break;
					}
				}
				sum *= Integer.parseInt(a);
				a = "";
			} else if (s[i] == '*') {
				i++;
				if (!a.equals("")) {
					sum += Integer.parseInt(a);
				}
				a = "";
				for (; i < s.length; i++) {
					if (s[i] != '*' && s[i] != '+') {
						a += s[i];
					} else {
						i--;
						break;
					}
				}
				sum += Integer.parseInt(a);
				a = "";
			} else {
				a += s[i];
			}
		}
		System.out.println(sum);
	}
}
0