結果

問題 No.49 算数の宿題
ユーザー scache
提出日時 2014-11-25 17:48:37
言語 Java
(openjdk 23)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 763 bytes
コンパイル時間 4,143 ms
コンパイル使用メモリ 75,208 KB
実行使用メモリ 41,644 KB
最終ジャッジ日時 2024-12-23 01:43:11
合計ジャッジ時間 5,812 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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