結果

問題 No.49 算数の宿題
ユーザー YamaKasaYamaKasa
提出日時 2018-06-24 18:02:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 119 ms / 5,000 ms
コード長 977 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 79,788 KB
実行使用メモリ 55,980 KB
最終ジャッジ日時 2023-08-24 17:39:44
合計ジャッジ時間 3,977 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,644 KB
testcase_01 AC 116 ms
54,248 KB
testcase_02 AC 116 ms
55,600 KB
testcase_03 AC 119 ms
55,980 KB
testcase_04 AC 117 ms
55,420 KB
testcase_05 AC 117 ms
53,772 KB
testcase_06 AC 118 ms
55,408 KB
testcase_07 AC 118 ms
55,872 KB
testcase_08 AC 116 ms
55,792 KB
testcase_09 AC 117 ms
55,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();
		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<String> ope = new ArrayList<String>();
		int begin = 0;
		for(int i = 0; i < S.length(); i++) {
			String o = S.substring(i, i + 1);
			if(o.equals("*") || o.equals("+")) {
				ope.add(o);
				list.add(Integer.parseInt(S.substring(begin, i)));
				begin = i + 1;
			}else {
				if(i == S.length() - 1) {
					list.add(Integer.parseInt(S.substring(begin, i + 1)));
				}
			}
		}
//		for(int n : list) {
//			System.out.println(n);
//		}
//		for(String o : ope) {
//			System.out.println(o);
//		}
		int ans = list.get(0);
		for(int i = 0; i < ope.size(); i++) {
			if(ope.get(i).equals("*")) {
				ans = ans + list.get(i + 1);
			}else {
				ans = ans * list.get(i + 1);
			}
		}
		System.out.println(ans);
	}
}
0