結果

問題 No.49 算数の宿題
ユーザー uafr_csuafr_cs
提出日時 2015-06-04 03:40:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 769 bytes
コンパイル時間 1,917 ms
コンパイル使用メモリ 72,780 KB
実行使用メモリ 56,376 KB
最終ジャッジ日時 2023-08-24 17:25:46
合計ジャッジ時間 3,758 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,120 KB
testcase_01 AC 114 ms
56,128 KB
testcase_02 AC 114 ms
55,632 KB
testcase_03 AC 114 ms
55,652 KB
testcase_04 AC 115 ms
56,100 KB
testcase_05 AC 113 ms
55,636 KB
testcase_06 AC 116 ms
56,172 KB
testcase_07 AC 115 ms
56,092 KB
testcase_08 AC 112 ms
56,376 KB
testcase_09 AC 112 ms
55,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		char[] inputs = sc.next().toCharArray();
		
		int pos = 0;
		int current = 0;
		while('0' <= inputs[pos] && inputs[pos] <= '9'){
			current *= 10;
			current += Character.getNumericValue(inputs[pos]);
			pos++;
		}
		
		while(pos < inputs.length){
			boolean plus = inputs[pos++] == '*';
			
			int snd = 0;
			while(pos < inputs.length && '0' <= inputs[pos] && inputs[pos] <= '9'){
				snd *= 10;
				snd += Character.getNumericValue(inputs[pos]);
				pos++;
			}
			
			if(plus){
				current += snd;
			}else{
				current *= snd;
			}
		}
		
		System.out.println(current);
	}
	
}
0