問題一覧 > 通常問題

No.1135 RPN

レベル : / AI推定難易度 : 167 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 135
作問者 : WrongAccept / テスター : leafirby
お気に入りにしたユーザー ProblemId : 4777 / 自分の提出
問題文最終更新日: 2020-07-26 22:33:13
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original

Problem Statement

You are given an expression in a certain notation consisting of $N$ elements. Output the result of evaluating this expression.

In this notation, an operator is written after its operands. In all other respects, it is the same as the usual infix notation.
Specifically, a b - means $a-b$.
Also, a b + c d + - means $a+b-(c+d)$.

Input

$N$
$A_1\ A_2\ A_3\ ....\ A_N$

$3\le N < 1000$
$N$ is an odd integer
$A_i$ is one of $+$, $-$, or an integer between $1$ and $100$, inclusive
$A$ is valid in the notation of this problem (more specifically, it is guaranteed that among the $A_i$ up to the $i$-th, the number of integers is always greater than the number of elements that are either of $+,-$, and that the total number of integers is exactly $\dfrac{(N+1)}{2}$.)

Output

Output the result of evaluating the given expression, followed by a newline.

Sample

Sample 1
Input
3
75 94 +
Output
169

Sample 2
Input
5
3 3 4 + +
Output
10

Sample 3
Input
5
5 7 - 5 +
Output
3

Source (the problem statement has been partially modified.)

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。