No.1135 RPN
タグ : / 解いたユーザー数 135
作問者 :
WrongAccept
/ テスター :
leafirby
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
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。