結果

問題 No.49 算数の宿題
ユーザー 37zigen37zigen
提出日時 2016-05-04 20:46:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 594 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 71,472 KB
実行使用メモリ 56,368 KB
最終ジャッジ日時 2023-08-24 17:32:00
合計ジャッジ時間 3,880 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,656 KB
testcase_01 AC 117 ms
55,712 KB
testcase_02 AC 116 ms
55,420 KB
testcase_03 AC 116 ms
56,368 KB
testcase_04 AC 117 ms
55,768 KB
testcase_05 AC 118 ms
55,960 KB
testcase_06 AC 117 ms
55,388 KB
testcase_07 AC 117 ms
55,984 KB
testcase_08 AC 116 ms
55,412 KB
testcase_09 AC 118 ms
55,396 KB
権限があれば一括ダウンロードができます

ソースコード

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