結果

問題 No.1135 RPN
ユーザー face4face4
提出日時 2020-08-04 21:51:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 3,190 ms
コンパイル使用メモリ 71,376 KB
実行使用メモリ 49,996 KB
最終ジャッジ日時 2023-10-12 23:12:13
合計ジャッジ時間 5,454 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
49,708 KB
testcase_01 AC 45 ms
49,356 KB
testcase_02 AC 48 ms
49,380 KB
testcase_03 AC 49 ms
49,996 KB
testcase_04 AC 51 ms
49,484 KB
testcase_05 AC 45 ms
47,216 KB
testcase_06 AC 51 ms
49,404 KB
testcase_07 AC 44 ms
49,356 KB
testcase_08 AC 45 ms
49,412 KB
testcase_09 AC 47 ms
49,364 KB
testcase_10 AC 50 ms
49,580 KB
testcase_11 AC 46 ms
49,384 KB
testcase_12 AC 51 ms
49,604 KB
testcase_13 AC 49 ms
49,384 KB
testcase_14 AC 51 ms
49,580 KB
testcase_15 AC 44 ms
49,248 KB
testcase_16 AC 44 ms
49,236 KB
testcase_17 AC 44 ms
49,552 KB
testcase_18 AC 44 ms
49,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Stack;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] line = br.readLine().split(" ");
        Stack<Integer> s = new Stack<Integer>();
        for(int i = 0; i < n; i++){
            if(line[i].equals("+")){
                s.push(s.pop()+s.pop());
            }else if(line[i].equals("-")){
                s.push(-s.pop()+s.pop());
            }else{
                s.push(Integer.parseInt(line[i]));
            }
        }
        System.out.println(s.peek());
    }
}
0