結果

問題 No.49 算数の宿題
ユーザー 37zigen
提出日時 2016-05-04 20:45:07
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 594 bytes
コンパイル時間 2,232 ms
コンパイル使用メモリ 74,412 KB
実行使用メモリ 54,356 KB
最終ジャッジ日時 2024-12-23 01:51:26
合計ジャッジ時間 4,292 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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