結果

問題 No.49 算数の宿題
ユーザー ぴろず
提出日時 2014-12-15 15:09:44
言語 Java
(openjdk 23)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 672 bytes
コンパイル時間 2,469 ms
コンパイル使用メモリ 74,792 KB
実行使用メモリ 41,172 KB
最終ジャッジ日時 2024-12-23 01:43:30
合計ジャッジ時間 4,110 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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