結果

問題 No.49 算数の宿題
ユーザー villachvillach
提出日時 2017-10-12 09:31:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 3,326 ms
コンパイル使用メモリ 75,264 KB
実行使用メモリ 56,044 KB
最終ジャッジ日時 2023-08-24 17:38:23
合計ジャッジ時間 5,312 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,776 KB
testcase_01 AC 121 ms
55,928 KB
testcase_02 AC 119 ms
55,784 KB
testcase_03 AC 119 ms
56,024 KB
testcase_04 AC 119 ms
55,864 KB
testcase_05 AC 119 ms
55,708 KB
testcase_06 AC 120 ms
55,548 KB
testcase_07 AC 120 ms
56,004 KB
testcase_08 AC 119 ms
55,976 KB
testcase_09 AC 123 ms
56,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class N49 {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String eq = sc.nextLine();
		int op = 0;
		int left_op = 0;
		int right_op = 0;
		int result = 0;
		int flag = 0;
		for(int i = 0;i < eq.length() + 1;++i){
			if(i == eq.length()){
				if(op == 1){
					left_op += right_op;
				}else if(op == 2){
					left_op *= right_op;
				}
				right_op = 0;
				break;
			}else if(eq.charAt(i) == 42){
				if(op == 1){
					left_op += right_op;
				}else if(op == 2){
					left_op *= right_op;
				}
				right_op = 0;
				op = 1; //たしざん
			}else if(eq.charAt(i) == 43){
				if(flag == 0){
					result = 1;
					flag = 1;
				}
				if(op == 1){
					left_op += right_op;
				}else if(op == 2){
					left_op *= right_op;
				}
				right_op = 0;
				op = 2; //かけざん
			}else if(op == 0){
				left_op *= 10;
				left_op += eq.charAt(i) - 48;
			}else{
				right_op *= 10;
				right_op += eq.charAt(i) - 48;
			}
		}
		
		System.out.println(left_op);
	}
}
0