結果

問題 No.49 算数の宿題
ユーザー kano_townkano_town
提出日時 2014-11-19 18:30:14
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 508 bytes
コンパイル時間 3,670 ms
コンパイル使用メモリ 74,196 KB
実行使用メモリ 41,224 KB
最終ジャッジ日時 2024-12-23 01:42:48
合計ジャッジ時間 5,726 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yukicoder49 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] a = s.split("[*+]");
		String sign = s.replaceAll("[0-9]", "");
		int res;

		res = Integer.parseInt(a[0]);
		for (int i = 1; i < a.length; i++) {
			if (sign.charAt(i - 1) == '*') res += Integer.parseInt(a[i]);
			else if (sign.charAt(i - 1) == '+') res *= Integer.parseInt(a[i]);
		}
		System.out.println(res);
	}
}
0