結果

問題 No.49 算数の宿題
ユーザー spaciaspacia
提出日時 2016-01-04 14:02:44
言語 Java19
(openjdk 21)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 654 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 71,820 KB
実行使用メモリ 50,464 KB
最終ジャッジ日時 2023-08-24 17:28:20
合計ジャッジ時間 3,075 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
49,728 KB
testcase_01 AC 47 ms
50,464 KB
testcase_02 AC 48 ms
49,736 KB
testcase_03 AC 51 ms
49,876 KB
testcase_04 AC 49 ms
49,908 KB
testcase_05 AC 47 ms
50,044 KB
testcase_06 AC 49 ms
49,736 KB
testcase_07 AC 48 ms
49,892 KB
testcase_08 AC 48 ms
49,660 KB
testcase_09 AC 48 ms
49,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.math.*;

class Main {
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		char[] c = br.readLine().toCharArray();
		boolean isAdd = true;
		int ans = 0, i = 0;
		
		while (i < c.length) {
			int work = 0;
			int j = i;
			while (j < c.length && (c[j] + "").matches("[0-9]")) {
				work = work * 10 + (c[j++] - '0');
			}
			ans = isAdd ? ans + work : ans * work;
			if (j < c.length) isAdd = c[j++] == '*';
			i = j;
		}
		
		out(ans);
	}
}
0