結果

問題 No.1135 RPN
ユーザー face4
提出日時 2020-08-04 21:51:37
言語 Java
(openjdk 23)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 2,918 ms
コンパイル使用メモリ 75,076 KB
実行使用メモリ 37,236 KB
最終ジャッジ日時 2024-09-14 21:19:52
合計ジャッジ時間 4,883 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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