結果

問題 No.1135 RPN
ユーザー xRS43BofaUEZ5gc
提出日時 2021-03-18 15:44:14
言語 Java
(openjdk 23)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 4,503 ms
コンパイル使用メモリ 75,364 KB
実行使用メモリ 41,212 KB
最終ジャッジ日時 2024-11-16 18:43:42
合計ジャッジ時間 6,924 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.Stack;


public class HelloWorld {
		public static void main (String[] args) {
			Scanner sc = new Scanner(System.in);
			int n = Integer.parseInt(sc.nextLine());
			String[] strs = sc.nextLine().split(" ");
			sc.close();

			Stack<Integer> stack = new Stack<Integer>();
			for (String str : strs) {
				if (str.equals("+")) {
					stack.push(stack.pop() + stack.pop());
				}
				else if (str.equals("-")) {
					stack.push(-stack.pop() + stack.pop());
				}
				else {
					stack.push(Integer.parseInt(str));
				}
			}
			System.out.println(stack.pop());


	}
}
0