結果

問題 No.49 算数の宿題
ユーザー shinwisteriashinwisteria
提出日時 2017-04-02 11:19:54
言語 Java19
(openjdk 21)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 1,060 bytes
コンパイル時間 3,223 ms
コンパイル使用メモリ 75,260 KB
実行使用メモリ 56,084 KB
最終ジャッジ日時 2023-08-24 17:36:56
合計ジャッジ時間 5,117 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
56,084 KB
testcase_01 AC 114 ms
53,992 KB
testcase_02 AC 116 ms
55,980 KB
testcase_03 AC 114 ms
55,736 KB
testcase_04 AC 115 ms
55,892 KB
testcase_05 AC 115 ms
55,740 KB
testcase_06 AC 119 ms
55,704 KB
testcase_07 AC 118 ms
55,912 KB
testcase_08 AC 117 ms
55,924 KB
testcase_09 AC 120 ms
55,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Sansunoshukudai {
	static StringBuilder str = new StringBuilder();

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		str.append(s.nextLine());
		s.close();
		int sum = 0;
		while(str.length() != 0){
			char c = str.charAt(0);
			if(c == '*'){
				str.deleteCharAt(0);
				sum += getnum();
			}else if(c == '+'){
				str.deleteCharAt(0);
				sum *= getnum();
			}else{
				sum += getnum();
			}
		}
		System.out.println(sum);

	}
	static int getnum(){
		int p = str.indexOf("*");
		int m = str.indexOf("+");
		int num = 0;
		if(p != -1 && m != -1){
			num = Integer.parseInt(str.substring(0, Math.min(p, m)));
			str.delete(0, Math.min(p, m));
		}else if(p != -1){
			num = Integer.parseInt(str.substring(0, p));
			str.delete(0, p);
		}else if(m != -1){
			num = Integer.parseInt(str.substring(0, m));
			str.delete(0, m);
		}else{
			num = Integer.parseInt(str.toString());
			str.delete(0, str.length());
		}
		return num;
	}

}
0