結果

問題 No.49 算数の宿題
ユーザー リチウムリチウム
提出日時 2014-10-23 23:06:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 543 bytes
コンパイル時間 6,150 ms
コンパイル使用メモリ 71,412 KB
実行使用メモリ 56,008 KB
最終ジャッジ日時 2023-08-24 17:22:43
合計ジャッジ時間 4,584 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,608 KB
testcase_01 AC 117 ms
55,552 KB
testcase_02 AC 119 ms
56,008 KB
testcase_03 AC 118 ms
55,564 KB
testcase_04 AC 117 ms
55,600 KB
testcase_05 AC 118 ms
55,660 KB
testcase_06 AC 120 ms
55,872 KB
testcase_07 AC 120 ms
55,760 KB
testcase_08 AC 116 ms
55,672 KB
testcase_09 AC 117 ms
55,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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