結果

問題 No.49 算数の宿題
ユーザー scachescache
提出日時 2014-11-25 17:48:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 763 bytes
コンパイル時間 2,990 ms
コンパイル使用メモリ 71,736 KB
実行使用メモリ 56,252 KB
最終ジャッジ日時 2023-08-24 17:24:10
合計ジャッジ時間 4,909 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
54,040 KB
testcase_01 AC 115 ms
56,252 KB
testcase_02 AC 112 ms
53,900 KB
testcase_03 AC 116 ms
56,088 KB
testcase_04 AC 113 ms
55,852 KB
testcase_05 AC 115 ms
56,200 KB
testcase_06 AC 115 ms
55,436 KB
testcase_07 AC 115 ms
55,760 KB
testcase_08 AC 113 ms
55,844 KB
testcase_09 AC 112 ms
55,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


import java.io.IOException;
import java.util.Scanner;

public class Main49 {
	public static void main(String[] args) {
		Main49 p = new Main49();
	}

	public Main49() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		solve(s);
		
	}

	public void solve(String s){
		int val = 0;
		char next = 0;
		int cur = 0;
		char lastop = '*';
		for(int i=0;i<s.length();i++){
			next = s.charAt(i);
			if('0' <= next && next <= '9'){
				cur = cur*10 + next-'0';
			}else if(next == '*' || next == '+'){
				if(lastop == '+')
					val *= cur;
				else
					val += cur;
				cur = 0;
				lastop = next;
			}
		}
		
		if(lastop == '+')
			val *= cur;
		else
			val += cur;
		
		System.out.println(val);
		
	}

}
0