Problem:


Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free.

Write a program which reads an expression in the Reverse Polish notation and prints the computational result.

An expression in the Reverse Polish notation is calculated using a stack. To evaluate the expression, the program should read symbols in order. If the symbol is an operand, the corresponding value should be pushed into the stack. On the other hand, if the symbols is an operator, the program should pop two elements from the stack, perform the corresponding operations, then push the result in to the stack. The program should repeat this operations.

Input

An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character.

You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106

Output

Print the computational result in a line.

Constraints

2 ≤ the number of operands in the expression ≤ 100

1 ≤ the number of operators in the expression ≤ 99

-1 &times; 109 ≤ values in the stack ≤ 109

Sample Input 1

1 2 +

Sample Output 1

3

Sample Input 2

1 2 + 3 4 - *

Sample Output 2

-3

Notes

Template in C



Sample input:
1 2 +


Sample output:
3

Submission status: Accepted

Solution code:
x = input()
y = x.split()
for i in range(len(y)):
    op = y[i]
    if op == '+' or op == '-' or op == '*':
        k = i-1
        for j in range(2):
            while 1:
                tmp = y[k]
                if tmp != '' and tmp != '+' and tmp != '-' and tmp != '*':
                    if j == 0:
                        nop_2 = int(y[k])
                        y[k] = ""
                        break
                    else:
                        nop_1 = int(y[k])
                        y[k] = ""
                        break
                k -= 1
                
        if op == '+':
            xRst = nop_1 + nop_2
        elif op == '-':
            xRst = nop_1 - nop_2
        else:
            xRst = nop_1 * nop_2
        y[i] = xRst
print(xRst)

Submission status: Accepted

Solution code:
class Stack():
    def __init__(self, size):
        self.A = [None for i in range(size)]
        self.i = -1  #最後に追加された要素が入っているIndex。Aが空の場合、-1
        self.size = size
    
    def push(self, x):
        self.A[self.i+1] = x
        self.i += 1
    
    def pop(self):
        ret = self.A[self.i]
        self.A[self.i] = None
        self.i -= 1
        return ret
    
    def isEmpty(self):
        return self.i == -1
    
    def isFull(self):
        return self.i == size - 1

S = Stack(100)
for i in input().split():
    if i == '+':
        s1, s2= S.pop(), S.pop()
        S.push(s2 + s1)
    elif i == '-':
        s1, s2= S.pop(), S.pop()
        S.push(s2 - s1)
    elif i == '*':
        s1, s2= S.pop(), S.pop()
        S.push(s2 * s1)
    else:
        S.push(int(i))
print(S.pop())

Submission status: Accepted

Solution code:
from collections import deque

*S, = input().split()
operater = '+-*'

stack = deque()

for s in S:
    if s in '+-*':
        b = stack.pop()
        a = stack.pop()

        if s == '+':
            stack.append(a+b)
        elif s == '-':
            stack.append(a-b)
        elif s == '*':
            stack.append(a*b)
    else:
        stack.append(int(s))

print(stack.pop())

Submission status: Accepted

Solution code:
def push(x):
    top[0] += 1
    stack[top[0]] = x
    return

def pop():
    top[0] -= 1
    return stack[top[0]+1] 

if __name__ == "__main__":
    stack = [0]*1000
    top = [0]
    for s in input().split():
        if s not in ("+","-","*"):
            push(int(s))
            continue
        a = pop()
        b = pop()
        if s == "+":
            push(b+a)
        elif s == "-":
            push(b-a)
        else:
            push(b*a)
    print(pop())

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self,arg_size):
        self.size = arg_size
        self.stack = [None] * self.size
        self.head = 0
        self.tail = 0

    def is_empty(self):
        return self.tail == self.head

    def push(self,arg_object):
        self.stack[self.tail] = arg_object
        self.tail += 1

    def pop(self):
        self.tail -= 1
        return self.stack[self.tail]

    def top(self):
        return self.stack[self.head]

SIZE = 105
NUM = Stack(SIZE)

input_str = list(map(str,input().split()))

for i in range(len(input_str)):
    ch = input_str[i]
    if ch in ['+','-','*']:
        num_2 = NUM.pop()
        num_1 = NUM.pop()
        num = 0
        if ch =='+':
            num =num_1+num_2
        elif ch =='-':
            num = num_1 - num_2
        else:
            num = num_1 * num_2
        NUM.push(num)
    else:
        NUM.push(int(ch))
print(NUM.top())

Submission status: Accepted

Solution code:
formula = input().split()
stack = []

for x in formula:
    if x.isdigit():
        stack.append(x)
    else:
        second_num = stack.pop()
        first_num = stack.pop()
        tmp = eval(first_num + x + second_num)
        stack.append(str(tmp))

print(int(stack.pop()))

Submission status: Accepted

Solution code:
# %%
class Stack:
    def __init__(self, size):
        self.size = size
        self.stack = [None] * self.size
        self.tail = 0

    def push(self, new):
        self.stack[self.tail] = new
        self.tail += 1

    def pop(self):
        self.tail -= 1
        return self.stack[self.tail]


max_size = 105

li = list(map(str, input().split()))
#li = ['1', '2', '+', '3', '4', '-', '*']
N = len(li)
stack = Stack(max_size)

for i in range(N):
    ch = li[i]
    if ch in ['+', '-', '*']:
        num_2 = stack.pop()
        num_1 = stack.pop()
        if ch == '+':
            stack.push(num_1 + num_2)
        elif ch == '-':
            stack.push(num_1 - num_2)
        else:
            stack.push(num_1 * num_2)
    else:
        stack.push(int(ch))

print('{}'.format(stack.stack[0]))


# %%

Submission status: Accepted

Solution code:
# list型でappend, popを用いると、Stackとして使うことができる。
# push -> append, pop -> pop
S = input().split()
s = []
for i in S:
    if i not in ['+', '-', '*']:
        s.append(int(i))
    else:
        s1 = s.pop()
        s2 = s.pop()
        if i == '+':
            s.append(s1 + s2)
        elif i == '-':
            s.append(s2 - s1)
        elif i == '*':
            s.append(s1 * s2)
print(s[0])

Submission status: Accepted

Solution code:
s = map(str, raw_input().split())

stack = []

for op in s:
  if op == '+':
    y = stack.pop()
    x = stack.pop()
    stack += [int(x) + int(y)]
  elif op == '-':
    y = stack.pop()
    x = stack.pop()
    stack += [int(x) - int(y)]
  elif op == '*':
    y = stack.pop()
    x = stack.pop()
    stack += [int(x) * int(y)]
  else:
    stack += [int(op)]
print stack[0]

Submission status: Accepted

Solution code:
def calc_formula(formula_list: list):
    operator = formula_list.pop()
    if formula_list[-1] in ['+', '-', '*']:
        back = calc_formula(formula_list)
    else:
        back = int(formula_list.pop())

    if formula_list[-1] in ['+', '-', '*']:
        front = calc_formula(formula_list)
    else:
        front = int(formula_list.pop())
    
    if operator == '+':
        return front + back

    if operator == '-':
        return front - back

    if operator == '*':
        return front * back

formula = input().split(' ')

res = calc_formula(formula)
print(res)

Submission status: Accepted

Solution code:
from collections import deque

L=input().split()

d = deque()

for l in L:
    if l in '+':
        a=d.pop()
        b=d.pop()
        d.append(a+b)
    elif l in '-':
        a=d.pop()
        b=d.pop()
        d.append(b-a)
    elif l in '*':
        a=d.pop()
        b=d.pop()
        d.append(a*b)
    elif l in '/':
        a=d.pop()
        b=d.pop()
        d.append(b/a)
    else:
        d.append(int(l))
        
print_num = d.pop()
print(print_num)

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp

class Stack(object):
    def __init__(self, num):
        self.list = []
        self.num = num
    
    def push(self, x):
        self.list.append(x)

    def pop(self):
        return self.list.pop(-1)
    
    def isEmpty(self):
        return len(self.list) == 0
    
    def isFull(self):
        return self.num <= len(self.list)



def main():
    li = list(input().split(' '))

    stack = Stack(999999)
    OPERANDS = ['+', '-', '*']
    
    for x in li:
        if not (x in OPERANDS):
            stack.push(int(x))
        else:
            b = stack.pop()
            a = stack.pop()

            if x == '+':
                stack.push(a + b)
            elif x == '-':
                stack.push(a - b)
            elif x == '*':
                stack.push(a * b)
        # print(stack.list)

    ans = stack.pop()
    print(ans)


        

main()

Submission status: Accepted

Solution code:
formula = input().split()
operand = ['+', '-', '*', '/']
stuck = []

for c in formula:
    if c in operand:
        b = str(stuck.pop())
        a = str(stuck.pop())
        stuck.append(eval(''.join([a, c, b])))
    else:
        stuck.append(c)

print(stuck.pop())

Submission status: Accepted

Solution code:
def onp(dzialanie):
    stos = []
    kolejka = dzialanie.split(" ")

    while len(kolejka) > 0:
        item = kolejka.pop(0)
        if item == "+":
            stos.append(stos.pop() + stos.pop())
        elif item == "-":
            odjemnik = stos.pop()
            stos.append(stos.pop() - odjemnik)
        elif item == "*":
            stos.append(stos.pop() * stos.pop())
        elif item == "/":
            dzielnik = stos.pop()
            stos.append(stos.pop() / dzielnik)
        else:
            try:
                stos.append(float(item))
            except ValueError:
                return "ERROR: Niedozwolony element: "+item

    return str(int(stos.pop()))

print(onp(input()))

Submission status: Accepted

Solution code:
a = input().split()
ret = 0
s = []
for e in a:
    if e in ["+","-","*"]:
        if e == "+":
            s.append(s.pop()+s.pop())
        elif e == "-":
            t = s.pop()
            s.append(s.pop()-t)
        else:# e == "*":
            s.append(s.pop()*s.pop())
    else:
        s.append(int(e))
print(s[0])

Submission status: Accepted

Solution code:
In = list(input().split())
stack = []

for x in In:
#まずは数字のときにstackに収納する
    if x.isdigit():
        stack.append(x)
#文字の時はその演算を行う
    else:
        second = stack.pop()
        first = stack.pop()
        tmp = eval(first + x + second)
        stack.append(str(tmp))

print(int(stack.pop()))

Submission status: Accepted

Solution code:
s = list(map(str, input().split()))
l = []
for i in range(len(s)):
    n = s[i]
    if n == "-":
        t = l.pop(-2) - l.pop(-1)
        l.append(t)
    elif n == "+":
        t = l.pop(-2) + l.pop(-1)
        l.append(t)
    elif n == "*":
        t = l.pop(-2) * l.pop(-1)
        l.append(t)
    else:
        l.append(int(n))

print(*l)

Submission status: Accepted

Solution code:
from collections import deque

tokens = input().split()
dq = deque()
operators = "+-*"
for token in tokens:
    if token in operators:
        a = dq.pop()
        b = dq.pop()
        if token == "+":
            dq.append(b + a)
        elif token == "-":
            dq.append(b - a)
        else:
            dq.append(b * a)
    else:
        dq.append(int(token))
print(dq.pop())

Submission status: Accepted

Solution code:
st = []
for i in input().split():
    if i in "+-*":
        v2 = st.pop()
        v1 = st.pop()
        st.append(str(eval(v1 + i + v2)))
    else:
        st.append(i)
print(st[0])

Submission status: Accepted

Solution code:
def ope(a, x, y):
    if a == '+':
        return x+y
    if a == '-':
        return x-y
    if a == '*':
        return x*y


*A, = input().split()
stack = []
for a in A:
    try:
        a = int(a)
        stack.append(a)
    except:
        tmp = stack.pop()
        tmp = ope(a, stack.pop(), tmp)
        stack.append(tmp)
print(stack.pop())

Submission status: Accepted

Solution code:
eq = input().split()
stack = []
for o in eq:
    if (o == '+'):
        a = int(stack.pop())
        b = int(stack.pop())
        stack.append(b+a)
    elif (o == '*'):
        a = int(stack.pop())
        b = int(stack.pop())
        stack.append(b*a)
    elif (o == '-'):
        a = int(stack.pop())
        b = int(stack.pop())
        stack.append(b-a)
    else:
        stack.append(o)
print(stack[0])

Submission status: Accepted

Solution code:
import collections 
S = list(input().split())
d = collections.deque()

for x in S:
    if x.isdecimal():
        d.append(x)
    else:
        second = d.pop()
        first = d.pop()
        d.append(str(eval(first + x + second)))
print(*d)

Submission status: Accepted

Solution code:
from collections import deque

ope = ["+","-","*","/"]

l = input().split()

d = deque()
while l:
    x = l.pop(0)
    if x in ope:
        n1 = d.pop()
        n2 = d.pop()
        val = str(n2)+x+str(n1)
        d.append(eval(val))
    else:
        d.append(x)
    
print(d.pop())

Submission status: Accepted

Solution code:
from collections import deque

d=deque()

A=input().split()

for n in range(len(A)):
    if A[n]=='+':
        a=int(d.pop())
        b=int(d.pop())
        d.append(str(b+a))
    elif A[n]=='-':
        a=int(d.pop())
        b=int(d.pop())
        d.append(str(b-a))
    elif A[n]=='*':
        a=int(d.pop())
        b=int(d.pop())
        d.append(str(b*a))
    else:
        d.append(int(A[n]))
        
print(int(d.pop()))

Submission status: Accepted

Solution code:
rpn=list(map(str, input().split()))

stack=[]

for token in rpn:
    if token in ("+", "-", "*", "/"):
        right=stack.pop()
        left=stack.pop()
        stack.append(str(eval(left+token+right)))
    else :
        stack.append(token)

print(stack.pop())

Submission status: Accepted

Solution code:
import sys
import math
import copy
from typing import Tuple, List
input = sys.stdin.readline

expressions = ["+", "-", "*"]
def calc_reverse_polish(formula: List) -> int:
    stack = []
    for icon in formula:
        if icon in expressions:
            v2 = stack.pop()
            v1 = stack.pop()
            stack.append(str(eval(v1 + icon + v2)))
        else:
            stack.append(icon)
    return stack

if __name__ == "__main__":
    A = input().split()
    stack = calc_reverse_polish(A)
    print(stack[0])

Submission status: Accepted

Solution code:
#alds13a
A = input().split(" ")
stack=[]
operator = ["+","-","*"]
for a in A:
    if a not in operator:
        stack.append(int(a))
    else:
        tmp=""
        if a=="+":
            tmp = stack[-2]+stack[-1]
        elif a=="-":
            tmp = stack[-2]-stack[-1]
        else:
            tmp = stack[-2]*stack[-1]
        stack = stack[:-2] + [tmp]
print(stack[0])

Submission status: Accepted

Solution code:
ope = {"+": lambda a, b: b + a,
       "-": lambda a, b: b - a,
       "*": lambda a, b: b * a}

stack = list()

for c in input().split():
    if c in ope:
        stack.append(ope[c](stack.pop(), stack.pop()))
    else:
        stack.append(int(c))

print(stack[-1])

Submission status: Accepted

Solution code:
class MyStack:
    def __init__(self, MAX):
        self.top = 0
        self.stack = [0] * MAX
        self.MAX = MAX
        
    def is_empty(self):
        return self.top <= 0
    
    def is_full(self):
        return self.top >= self.MAX - 1
    
    def push(self, entry):
        if self.is_full():
            raise ValueError()
        self.top += 1
        self.stack[self.top] = entry
    
    def pop(self):
        if self.is_empty():
            raise ValueError()
        self.top -= 1
        return self.stack[self.top + 1]
    
    
stack = MyStack(110)
ope = input().split()

for o in ope:
    if o == '+':
        rh = stack.pop()
        lh = stack.pop()
        stack.push(lh + rh)
        
    elif o == '-':
        rh = stack.pop()
        lh = stack.pop()
        stack.push(lh - rh)
        
    elif o == '*':
        rh = stack.pop()
        lh = stack.pop()
        
        stack.push(lh * rh)
        
    else:
        stack.push(int(o))

result = stack.pop()
print(result)

Submission status: Accepted

Solution code:
N = list(input().split())
S = []

for i in N:
    a = 0
    b = 0
    if i == '+':
        a = S.pop()
        b = S.pop()
        S.append(a+b)
    elif i == '-':
        a = S.pop()
        b = S.pop()
        S.append(b-a)
    elif i == '*':
        a = S.pop()
        b = S.pop()
        S.append(a*b)
    elif i == '/':
        a = S.pop()
        b = S.pop()
        S.append(a//b)
    else:
        S.append(int(i))

print(S[0])

Submission status: Accepted

Solution code:
import collections

letter = input().split(' ')
stack = collections.deque(letter.pop())


def calc_chk(num1, num2, op):
    if op in ['+', '-', '*'] and num1 not in ['+', '-', '*'] and num2 not in ['+', '-', '*']:
        return True
    else:
        return False

while letter:
    temp = letter.pop()
    stack.append(temp)

    is_calc = True
    while is_calc:
        # print(stack)
        if len(stack) >=3:
            if calc_chk(stack[-1], stack[-2], stack[-3]):
                num1 = stack.pop()
                num2 = stack.pop()
                op = stack.pop()
                val = str(eval(num1 + op + num2))
                stack.append(val)
    
            else:
                is_calc = False
        else:
            is_calc = False
print(*stack)

Submission status: Accepted

Solution code:
inputs = list(input().split())
stack = []

for i in range(len(inputs)):
    if inputs[i] in ('+', '-', '*'):
        ope = inputs[i]
        if ope == '+':
            stack.append(stack.pop() + stack.pop())
        elif ope == '-':
            stack.append(-stack.pop() + stack.pop())
        elif ope == '*':
            stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(inputs[i]))

print(stack.pop())

Submission status: Accepted

Solution code:
s = []
for v in input().split():
    if v in '+-*':
        a, b = s.pop(), s.pop()
        s.append(str(eval(b + v + a)))
    else:
        s.append(v)
print(s[0])

Submission status: Accepted

Solution code:
def push(s,x):
    s.append(x)
    return(s)

def pop(s):
    ind = len(s)
    a = s[ind-1]
    del s[ind-1]
    return(s, a)



A = input().split()
n = len(A)

stack = []

for i in range(n):
    if (A[i] == '+') or (A[i] == '-') or (A[i] == '*'):
        stack, b = pop(stack)
        stack, a = pop(stack)
        if A[i] == '+':
            stack = push( stack, (int(a)+int(b)) )
        elif A[i] == '-':
            stack = push( stack, (int(a)-int(b)) )
        else:
            stack = push( stack, (int(a)*int(b)) )
    else:
        push(stack, A[i])

print(stack[0])

Submission status: Accepted

Solution code:
L=list(input().split())
s=[]
for l in L:
  s.append(l)
  if l in ['+','-','*']:
    op=s.pop()
    b=int(s.pop())
    a=int(s.pop())
    s.append(a+b) if op=='+' else s.append(a-b) if op=='-' else s.append(a*b)
print(s[0])

Submission status: Accepted

Solution code:
X = list(map(str, input().split()))
A = []
for x in X:
    if x.isnumeric():
        A.append(int(x))
    else:
        a = A.pop()
        b = A.pop()
        if x == '+':
            A.append(a+b)
        elif x == '-':
            A.append(b-a)
        else:
            A.append(a*b)
print(A[0])

Submission status: Accepted

Solution code:
s = input().split(" ")

operand = ["+", "-", "*"]
stack = []
for i in s:
    if i in operand:
        a = stack.pop()
        b = stack.pop()
        stack.append(eval(str(b) + i + str(a)))
    else :
        stack.append(i)
print(stack[0])

Submission status: Accepted

Solution code:
from collections import deque


def main():
    S = [s for s in input().split()]
    ops = ['+', '-', '*']
    
    d = deque()
    for s in S:
        if s in ops:
            b, a = d.pop(), d.pop()
            eq = a + s + b
            v = eval(eq)
            d.append(str(v))
        else:
            d.append(s)
            
    print(v)
 
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
a = list(map(str,input().split()))
S = []
top = -1
for i in range(len(a)):
    if a[i].isdigit()==True:
        top+=1
        #print('数値')
        S.append(int(a[i]))
        #print(S)
    else:
        #print('not')
        operand = a[i]
        b = S.pop()
        c = S.pop()
        if operand =='+':
            S.append(c + b)
        if operand =='-':
            S.append(c - b)
        if operand =='*':
            S.append(c * b)
        #print(S)
        #top-=2
print(*S)

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self, max):
        self.max = max
        self.data = list(range(max))
        self.top = 0
    def initialize(self):
        self.top = 0
    def isEmpty(self):
        return self.top == 0
    def isFull(self):
        return self.top >= len(self.data)
    def push(self, x):
        #TODO: if isFull: error
        self.top += 1
        self.data[self.top] = x
    def pop(self):
        #TODO: if isEmpty: error
        self.top -= 1
        return self.data[self.top+1]

D = input().split()
# D = ['1', '2', '+', '3', '4', '-', '*']

s = Stack(300)

for i in range(len(D)):
    s.push(D[i])
    if D[i] == '+' or D[i] == '-' or D[i] == '*' or D[i] == '/':
        operator = s.pop()
        operand2 = s.pop()
        operand1 = s.pop()
        temp = eval(operand1 + operator + operand2)
        s.push(str(temp))
        # print('i: ' + str(i) + ' result: ' + str(temp) + '   ' + operand1 + operator + operand2)
print(s.pop())

Submission status: Accepted

Solution code:
class Stack:
    def __init__(self):
        self.stack = []

    def push(self, num):
        self.stack.append(num)

    def pop(self):
        return self.stack.pop()

    def calc(self, ope):
        ans = 0
        num1 = self.pop()
        num2 = self.pop()
        if ope == '+':
            ans = num2 + num1
        elif ope == '-':
            ans = num2 - num1
        elif ope == '*':
            ans = num2 * num1
        self.push(ans)


stack = Stack()
input_list = input().split()
for i in input_list:
    if i.isdecimal():
        stack.push(int(i))
    else:
        stack.calc(i)
print(stack.pop())

Submission status: Accepted

Solution code:
def stack(data):
    s = []
    for i in data:
        if i in "+-*":
            a2 = s.pop()
            a1 = s.pop()
            s.append(str(eval(a1 + i + a2)))
        else:
            s.append(i)
    print(s[0])

if "__main__" == __name__:
    data = input().split()
    stack(data)

Submission status: Accepted

Solution code:
inp = input().split()

stack = []
for i in range(len(inp)):
    if inp[i].isdecimal():
        stack.append(inp[i])
    else:
        a = int(stack.pop())
        b = int(stack.pop())
        
        if inp[i] == "+":
            stack.append(b + a)
        elif inp[i] == "-":
            stack.append(b - a)
        elif inp[i] == "*":
            stack.append(b * a)

print(*stack)

Submission status: Accepted

Solution code:
from collections import deque

def main():
    stack = deque()

    for c in input().split(" "):

        if c.isdecimal():
            stack.append(int(c))
        
        elif c == "+" or c == "-" or c == "*":
            v1 = stack.pop()
            v2 = stack.pop()
            if c == "+":
                stack.append(v1 + v2)
            elif c == "-":
                stack.append(v2 - v1)
            elif c == "*":
                stack.append(v1 * v2)

    print(stack.pop())

main()

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001



class Stack:
    def __init__(self,arg_size):
        self.size = arg_size
        self.stack = [None] * self.size
        self.head = 0
        self.tail = 0

    def is_empty(self):
        return self.tail == self.head

    def push(self,arg_object):
        self.stack[self.tail] = arg_object
        self.tail += 1

    def pop(self):
        self.tail -= 1
        return self.stack[self.tail]

    def top(self):
        return self.stack[self.head]


SIZE = 105
NUM = Stack(SIZE)

input_str = list(map(str,input().split()))

for i in range(len(input_str)):
    ch = input_str[i]
    if ch in ['+','-','*']:
        num_2 = NUM.pop()
        num_1 = NUM.pop()
        num = 0
        if ch == '+':
            num = num_1+num_2
        elif ch == '-':
            num = num_1-num_2
        else:
            num = num_1*num_2
        NUM.push(num)
    else:
        NUM.push(int(ch))

print("%d"%(NUM.top()))

Submission status: Accepted

Solution code:
def stack():
    S = list(input().split())
    N = len(S)

    A = [0]

    for i in range(N):
        if S[i] == '+':
            A[-2] += A[-1]
            A.pop()
        elif S[i] == '-':
            A[-2] -= A[-1]
            A.pop()
        elif S[i] == '*':
            A[-2] *= A[-1] #演算は常に「最新の２つの数字」について行われる事を利用
            A.pop()
        elif S[i] == '/':
            A[-2] /= A[-1]
            A.pop()
        else:
            A.append(int(S[i]))
    
    print(A[-1])

stack()

Submission status: Accepted

Solution code:
arr = [ i for i in input().split(" ")]

# 1 2 +
operands = ["+", "-", "*", "/"]

s = []

for i in arr:
  if i not in operands:
    s.append(i)
  
  if i in operands:
    val2 = s.pop()
    val1 = s.pop()

    s.append(eval("{0} {1} {2}".format(val1, i, val2)))

print(s[-1])

Submission status: Accepted

Solution code:
#Stack
class Node:
    def __init__(self, data):
        self.next = None
        self.data = data

class Stack:
    def __init__(self):
        self.top = None
    
    def push(self,data):
        node = Node(data)
        if self.top==None:
            self.top = node
        else:
            node.next = self.top
            self.top = node
            
    def pop(self):
        if self.top==None:
            return
        else:
            out = self.top
            self.top = self.top.next
            return out

def calc_rpn(x):
    if x=="+" or x=="-" or x=="*":
        a = stack.pop().data
        b = stack.pop().data
        if x=="+":
            stack.push(b + a)
        elif x=="-":
            stack.push(b - a)
        elif x=="*":
            stack.push(b * a)
        
    else:
        stack.push(int(x))

inp = list(input().split())
stack = Stack()

for x in inp:
    calc_rpn(x)
print(stack.pop().data)

Submission status: Accepted

Solution code:
def main():
    stack = list(input().split(' '))
    stack_x = list()
    for s in stack:
        try:
            int(s)
            stack_x.append(s)
        except ValueError:
            y = stack_x.pop()
            x = stack_x.pop()
            stack_x.append(eval(str(f'{x}{s}{y}')))
    print(*stack_x)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#入力dataの格納
input_list = list(map(str, input().split()))

#計算
i = 0
while len(input_list) > 1:
    if input_list[i] == "+":
        input_list.insert(i+1, int(input_list[i-2]) + int(input_list[i-1]))
        del input_list[i-2: i+1]
        i = 0
    elif input_list[i] == "-":
        input_list.insert(i+1, int(input_list[i-2]) - int(input_list[i-1]))
        del input_list[i-2: i+1]
        i = 0
    elif input_list[i] == "*":
        input_list.insert(i+1, int(input_list[i-2]) * int(input_list[i-1]))
        del input_list[i-2: i+1]
        i = 0
    i += 1

#計算結果の表示
print(input_list[-1])

Submission status: Accepted

Solution code:
a=input().split()
b=[]
for i in range(len(a)):
    if a[i]=='*':
        b.append(int(b.pop()) *int(b.pop()))
    elif a[i]=='+':
        b.append(int(b.pop()) +int(b.pop()))
    elif a[i]=='-':
        b.append(-int(b.pop()) +int(b.pop()))
    else:
        b.append(int(a[i]))
print(b[0])

Submission status: Accepted

Solution code:
# Algorithms and Data Structures 1
# Stack
# Name: Ryuya Asada
# ID: s1260064


class Stack():
    def __init__(self, size):
        self.__top = 0
        self.__stack = [int] * (size+1)

    def isEmpty(self) -> bool:
        return self.__top == 0

    def isFull(self) -> bool:
        return self.__top >= len(self.__stack)-1

    def push(self, x):
        if self.isFull():
            print("Overflow!")
        
        self.__top += 1
        self.__stack[self.__top] = x

    def pop(self):
        if self.isEmpty():
            print("Underflow!")

        self.__top -= 1
        return self.__stack[self.__top+1]


def main():
    s = Stack(100)
    operation = input().split(" ")
    for o in operation:
        if o == '+':
            a, b = s.pop(), s.pop()
            s.push(a + b)
        elif o == '-':
            b, a = s.pop(), s.pop()
            s.push(a - b)
        elif o == '*':
            a, b = s.pop(), s.pop()
            s.push(a * b)
        else:
            s.push(int(o))

    print(s.pop())


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
top = 0
s = [0]*1000

def push(x):
    global top
    top += 1
    s[top] = x
    
def pop():
    global top
    top -= 1
    return s[top+1]

a = list(input().split())

for x in a:
    if x == "+":
        b = pop()
        c = pop()
        push(b+c)
    elif x == "-":
        b = pop()
        c = pop()
        push(c-b)
    elif x == "*":
        b = pop()
        c = pop()
        push(b*c)
    else:
        push(int(x))

print(pop())

Submission status: Accepted

Solution code:
S = input().split()
stack = []

operator = ['+', '-', '*']

for i in range(len(S)):
    if not(S[i] in operator):
        stack.append(int(S[i]))
    elif S[i] == operator[0]:
        a = stack.pop()
        b = stack.pop()
        stack.append(a + b)
    elif S[i] == operator[1]:
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif S[i] == operator[2]:
        a = stack.pop()
        b = stack.pop()
        stack.append(a * b)
print(stack[0])

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    exp = input().split()

    operator = None
    stack = []
    for e in exp:
        if e == '+':
            r = int(stack.pop())
            l = int(stack.pop())
            stack.append(l+r)
        elif e == '-':
            r = int(stack.pop())
            l = int(stack.pop())
            stack.append(l-r)
        elif e == '*':
            r = int(stack.pop())
            l = int(stack.pop())
            stack.append(l*r)
        else:
            stack.append(int(e))
        # print('stack: {}'.format(stack))

    print(stack.pop())

Submission status: Accepted

Solution code:
#  stack

lst = input().split()

stack = []
for arg in lst:

    if arg == "+":
        tmp = int(stack.pop())
        stack.append(int(stack.pop()) + tmp)
    elif arg == "-":
        tmp = int(stack.pop())
        stack.append(int(stack.pop()) - tmp)
    elif arg == "*":
        tmp = int(stack.pop())
        stack.append(int(stack.pop()) * tmp)
    else:
        stack.append(int(arg))

print(stack[0])

Submission status: Accepted

Solution code:
s = input().split()
l = []
for i in range(len(s)):
    p = ""
    if s[i].isdecimal() == False:
        x = l.pop()
        y = l.pop()
        p += y + s[i] + x
        l.append(str(eval(p)))
    else:
        l.append(s[i])
print(l[0])