結果

問題 No.49 算数の宿題
コンテスト
ユーザー shinwisteria
提出日時 2017-04-02 11:19:54
言語 Java
(openjdk 27 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,060 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,746 ms
コンパイル使用メモリ 87,540 KB
実行使用メモリ 45,264 KB
最終ジャッジ日時 2026-10-11 22:55:39
合計ジャッジ時間 4,451 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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