結果

問題 No.49 算数の宿題
コンテスト
ユーザー 37zigen
提出日時 2016-05-04 20:46:43
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 594 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,593 ms
コンパイル使用メモリ 82,044 KB
実行使用メモリ 41,400 KB
最終ジャッジ日時 2026-05-29 04:40:59
合計ジャッジ時間 3,099 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

package yukicoder;
import java.util.Scanner;
public class Main{
	public static void main(String[] args)throws Exception{
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		char[] c=sc.next().toCharArray();
		int n=c.length;
		int now=0;
		boolean tasu=true;
		int ans=0;
		for(int i=0;i<n;i++){
			if(c[i]-'0'>=0&&c[i]-'0'<=9){
				now*=10;
				now+=c[i]-'0';
			}
			else{
				if(tasu)ans+=now;
				else ans*=now;
				now=0;
				if(c[i]=='+')tasu=false;
				else if(c[i]=='*')tasu=true;
			}
		}
		if(tasu)ans+=now;
		else ans*=now;
		System.out.println(ans);
	}
}
0