結果

問題 No.49 算数の宿題
ユーザー ぴろずぴろず
提出日時 2014-12-15 15:09:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 672 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 73,920 KB
実行使用メモリ 39,796 KB
最終ジャッジ日時 2023-08-24 17:24:31
合計ジャッジ時間 4,116 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
39,144 KB
testcase_01 AC 118 ms
39,368 KB
testcase_02 AC 118 ms
39,076 KB
testcase_03 AC 117 ms
39,228 KB
testcase_04 AC 116 ms
39,032 KB
testcase_05 AC 119 ms
39,796 KB
testcase_06 AC 118 ms
39,068 KB
testcase_07 AC 118 ms
38,940 KB
testcase_08 AC 120 ms
39,468 KB
testcase_09 AC 119 ms
39,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no049;

import java.util.Scanner;

public class Main {

	static char[] s;
	static int i;
	static int n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		s = sc.next().toCharArray();
		n = s.length;
		i = 0;
		System.out.println(exp());
	}

	public static int exp() {
		int num = number();
		while(i < n) {
			if (s[i] == '*') {
				i++;
				num += number();
			}else{
				i++;
				num *= number();
			}
		}
		return num;
	}

	public static int number() {
		int num = 0;
		while (i < n && '0' <= s[i] && s[i] <= '9') {
			num *= 10;
			num += s[i] - '0';
			i++;
		}
		return num;
	}

}
0