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:
def ope(a,b,v):
  if v == '+':
    return a + b
  elif v == '-':
    return a - b
  elif v == '*':
    return a * b
  
stacs = list(input().split())
n = len(stacs)
flag = 1
t = []
for i in range(n):
  if stacs[i] != '+' and stacs[i] != '-' and stacs[i] != '*':
    t.append(int(stacs[i]))
  else:
    max = len(t)
    vv = ope(t[max-2],t[max-1],stacs[i])
    del t[max-2:max]
    t.append(vv)
print(t[0])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    l = []

    IN = input().split()
    for c in IN:
        if c.isnumeric():
            l.append(int(c))
        else:
            b = l.pop()
            a = l.pop()

            if c == '+':
                ans = a + b
            elif c == '*':
                ans = a * b
            elif c == '-':
                ans = a - b

            l.append(ans)

    print(l[0])

Submission status: Accepted

Solution code:
stack=list(input().split())
num_stack=[]
while len(stack) != 0:
    if stack[0] == '+':
        num=num_stack[len(num_stack)-1] + num_stack[len(num_stack)-2]
        num_stack.pop(len(num_stack)-1)
        num_stack.pop(len(num_stack)-1)        
        num_stack.append(num)
        stack.pop(0)
    elif stack[0] == '-':
        num=num_stack[len(num_stack)-2] - num_stack[len(num_stack)-1]
        num_stack.pop(len(num_stack)-1)
        num_stack.pop(len(num_stack)-1)  
        num_stack.append(num)
        stack.pop(0)
    elif stack[0] == '*':
        num=num_stack[len(num_stack)-1] * num_stack[len(num_stack)-2]
        num_stack.pop(len(num_stack)-1)
        num_stack.pop(len(num_stack)-1)  
        num_stack.append(num)
        stack.pop(0)
    else:
        num_stack.append(int(stack.pop(0)))
print(num_stack[0])

Submission status: Accepted

Solution code:
st = []
for c in input().split():
    if c in "+-*":#演算子がでてきたら
        v2 = st.pop()
        v1 = st.pop()
        st.append(str(eval(v1 + c + v2)))
    else: #普通の数値
        st.append(c)
print(st[0])

Submission status: Accepted

Solution code:
class ArrayDeque:
    def __init__(self):
        self.a_size = 1
        self.a = [None]
        self.n = 0
        self.head = 0
        self.tail = 0

    def __bool__(self):
        return self.n != 0

    def _resize(self):
        new_a = [None] * ((self.n + 1) << 1)
        for i in range(self.n):
            new_a[i] = self.a[(self.head + i) & (self.a_size - 1)]
        self.a = new_a
        self.a_size = (self.n + 1) << 1
        self.head = 0
        self.tail = self.n

    def append(self, val):
        if self.n == self.a_size - 1:
            self._resize()
        self.a[self.tail] = val
        self.tail = (self.tail + 1) & (self.a_size - 1)
        self.n += 1

    def appendleft(self, val):
        if self.n == self.a_size - 1: 
            self._resize()
        self.head = (self.head - 1) & (self.a_size - 1)
        self.a[self.head] = val
        self.n += 1

    def popleft(self):
        if self.n == 0:
            raise IndexError()
        val = self.a[self.head]
        self.head = (self.head + 1) & (self.a_size - 1)
        self.n -= 1
        if self.a_size >= 4 * self.n + 2:
            self._resize()
        return val

    def pop(self):
        if self.n == 0:
            raise IndexError()
        self.tail = (self.tail - 1) & (self.a_size - 1)
        val = self.a[self.tail]
        self.n -= 1
        if self.a_size >= 4 * self.n + 2:
            self._resize()
        return val


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

for item in a:
    if item == '+':
        a = stack.pop()
        b = stack.pop()
        stack.append(b + a)
    elif item == '-':
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif item == '*':
        a = stack.pop()
        b = stack.pop()
        stack.append(b * a)
    else:
        stack.append(int(item))

ans = stack.pop()
print(ans)

Submission status: Accepted

Solution code:
a = list(input().split())

stack = []
for v in a:
    if not v.isdigit():
        y = stack.pop(len(stack)-1)
        x = stack.pop(len(stack)-1)
        if v == '+':
            stack.append(x + y)
        elif v == '-':
            stack.append(x - y)
        elif v == '*':
            stack.append(x * y)
        else:
            stack.append(x / y)

    else:
        try:
            stack.append(int(v))
        except ValueError:
            stack.append(float(v))

print('{}'.format(stack.pop(0)))

Submission status: Accepted

Solution code:
def calc(expression):
    stack = []
    for i in expression:
        if i == '+':
            b, a = stack.pop(), stack.pop()
            stack.append(a + b)
            
        elif i == '-':
            b, a = stack.pop(), stack.pop()
            stack.append(a - b)
            
        elif i == '*':
            b, a = stack.pop(), stack.pop()
            stack.append(a * b)
            
        elif i == '/':
            b, a = stack.pop(), stack.pop()
            stack.append(a // b)
            
        else:
            stack.append(int(i))
    
    return stack[0]
n = input().split() 
print(calc(n))

Submission status: Accepted

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

for op in eq:
    if op == "+":
        x = stack.pop() + stack.pop()
        stack.append(x)
    elif op == "-":
        x1 = stack.pop()
        x2 = stack.pop()
        stack.append(x2 - x1)
    elif op == "*":
        x = stack.pop() * stack.pop()
        stack.append(x)
    else:
        stack.append(int(op))

print(stack[0])

Submission status: Accepted

Solution code:
datas = list(map(str,input().split(' ')))
tmp = list()
operator_list = ['+', '-', '*', '/']

for data in datas:
    if operator_list[0] == data:
        tmp.append(tmp.pop() + tmp.pop())
    elif operator_list[1] == data:
        tmp.append(0 - tmp.pop() + tmp.pop())
    elif operator_list[2] == data:
        tmp.append(tmp.pop() * tmp.pop())
    elif operator_list[3] == data:
        tmp.append(1 / tmp.pop() * tmp.pop())
    else:
        tmp.append(int(data))

print(tmp.pop())

Submission status: Accepted

Solution code:
def readinput():
    s = input().split()
    return s

def main(s):
    stack=[]
    ans = 0
    i = 0
    for c in s:
        if (c=='+'):
            op1 = int(stack.pop())
            op2 = int(stack.pop())
            stack.append(str(op1+op2))
        elif(c=='-'):
            op1 = int(stack.pop())
            op2 = int(stack.pop())
            stack.append(str(op2-op1))
        elif(c=='*'):
            op1 = int(stack.pop())
            op2 = int(stack.pop())
            stack.append(str(op1*op2))
        else:
            stack.append(c)
    ans = int(stack.pop())    
    return ans

if __name__=='__main__':
    s = readinput()
    ans = main(s)
    print(ans)

Submission status: Accepted

Solution code:
from typing import  Any

class FixedStack:
    class Empty(Exception):
        pass
    class Full(Exception):
        pass
    def __init__(self, capacity:int = 256) -> None:
        self.stk = [None] * capacity
        self.capacity = capacity
        self.ptr = 0

    def __len__(self) -> int:
        return  self.ptr

    def is_empty(self) -> bool:
        return  self.ptr <= 0

    def is_full(self) -> bool:
        return  self.ptr >= self.capacity

    def push(self, value: Any) ->None:
        if self.is_full():
            raise FixedStack.Full
        self.stk[self.ptr] = value
        self.ptr += 1

    def pop(self) -> Any:
        if self.is_empty():
            raise FixedStack.Empty
        self.ptr -= 1
        return self.stk[self.ptr]

    def peek(self) -> Any:
        if self.is_empty():
            raise FixedStack.Empty
        return self.stk[self.ptr - 1]


S = FixedStack(100)

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

for i in range(len(A)):
    ch = A[i]
    if ch in ['+', '-', '*', '/']:
        num2 = S.pop()
        num1 = S.pop()
        num = 0
        if ch == '+':
            num = num1 + num2
        elif ch == '-':
            num = num1 - num2
        elif ch == '*':
            num = num1 * num2
        elif ch == '/':
            num = num1 / num2
        S.push(num)
    else:
        S.push(int(ch))

print(S.peek())

Submission status: Accepted

Solution code:
S =[]
S.append(0)
top = 0
MAX = 1000
t = 0

def initialize():
    top = 0

def isEmpty():
    return top == 0

def isFull():
    return top >= MAX - 1

def push(x):
    global top
    if isFull():
        print("error")
    top += 1
    S.append(x)

def pop():
    global top
    global t
    t = 0
    if isEmpty():
        print("error")
    top -= 1
    t = S[top + 1]
    del S[top + 1]
    return t

L = input().split()

for i in range(len(L)):
    if L[i] == "+":
        push(int(pop()) + int(pop()))
    elif L[i] == "-":
        push(-(int(pop()) - int(pop())))
    elif L[i] == "*":
        push(int(pop()) * int(pop()))
    else:
        push(L[i])
print(S[top])

Submission status: Accepted

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

def inv_porland_math(In):
    stack = []
    for m in In:
        if(m == "+"):
            stack.append(stack.pop(-2) + stack.pop(-1))
        elif(m == "-"):
            stack.append(stack.pop(-2) - stack.pop(-1))
        elif(m == "*"):
            stack.append(stack.pop(-1) * stack.pop(-1))
        else:
            stack.append(int(m))
    return stack[0]

ans = inv_porland_math(In)
print(ans)

Submission status: Accepted

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

ans = []
for f in formula:
    if f == '+':
        a = ans.pop()
        b = ans.pop()
        ans.append(a + b)
    elif f == '-':
        a = ans.pop()
        b = ans.pop()
        ans.append(b - a)
    elif f == '*':
        a = ans.pop()
        b = ans.pop()
        ans.append(b * a)
    else:
        ans.append(int(f))

print(*ans)

Submission status: Accepted

Solution code:
n = list(map(str,input().split()))
a = []
for i in range(len(n)):
  b = n[i]
  if b =="+":
    k = int(a.pop())
    l = int(a.pop())
    a.append(k+l)
  elif b =='-':
    k = int(a.pop())
    l = int(a.pop())
    a.append(l-k)
  elif b=='*':
    k = int(a.pop())
    l = int(a.pop())
    a.append(k*l)
  else :
    a.append(b)
print(*a)

Submission status: Accepted

Solution code:
def revPolish(input_list):
    stack_list = list()

    for data in input_list:
        if data.isdecimal():
            stack_list.append(int(data))
        else:
            a, b = [stack_list.pop(), stack_list.pop()]
            if data == '+':
                stack_list.append(b + a)
            elif data == '-':
                stack_list.append(b - a)
            elif data == '*':
                stack_list.append(b * a)

    return stack_list[0]


if __name__ == "__main__":
    print(revPolish(input().split()))

Submission status: Accepted

Solution code:

from collections import deque

com = input().split()
dq = deque()

for op in com:
    if op == '+':
        a = dq.pop()
        b = dq.pop()
        dq.append(a+b)
    elif op == '*':
        a = dq.pop()
        b = dq.pop()
        dq.append(a*b)
    elif op == '-':
        a = dq.pop()
        b = dq.pop()
        dq.append(b-a)
    else :
        dq.append(int(op))
print (dq.pop())

Submission status: Accepted

Solution code:
data = list(input().split(" "))
stack = []
for d in data:
    if d == '+':
        stack.append(stack.pop() + stack.pop())
    elif d == '-':
        stack.append(- stack.pop() + stack.pop())
    elif d == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(d))
print(stack[0])

Submission status: Accepted

Solution code:
def calc(E,A):
  if len(A) >= 2:
    a2 = int(A.pop())
    a1 = int(A.pop())
    if E == '*' :
      a3 = a1 * a2
    elif E == '+':
      a3 = a1 + a2
    elif E == '-':
      a3 = a1 - a2
    A.append(a3)
    

E = list(input().split())
a = []
for e in E:
  if (e == '+' or e == '-' or e == '*') :
    calc(e,a)
  else:
    a.append(e)

print(a[0])

Submission status: Accepted

Solution code:
# https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_3_A

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


def is_op(s):
    if s == '+' or s == '-' or s == '*':
        return True
    return False


a2 = []
for s in a:
    if is_op(s):
        n2 = a2.pop()
        n1 = a2.pop()
        a2.append(eval(str(n1) + s + str(n2)))
    else:
        a2.append(int(s))

print(a2.pop())

Submission status: Accepted

Solution code:
l = []
l = input().split()

stack = []

def ReversePolishNotation(i):
    global l
    if l[i] == '+' :
        b = mypop()
        a = mypop()
        push(a+b)
    elif l[i] == '-':
        b = mypop()
        a = mypop()
        push(a-b)
    elif l[i] == '*':
        b = mypop()
        a = mypop()
        push(a*b)
    else:
        push(int(l[i]))


def mypop():
    global stack
    return stack.pop(-1)

def push(n):
    global stack
    stack.append(n)


for i in range(len(l)):
    ReversePolishNotation(i)

print(mypop())

Submission status: Accepted

Solution code:
class Stack:

    def __init__(self):
        self.stack = []

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

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

    def IsEmpty(self):
        return len(self.stack) == 0

def Reverse_polish(lst):
    stack = Stack()
    for i in range(len(lst)):
        if lst[i] == "+":
            a = stack.pop()
            b = stack.pop()
            stack.push(a + b)
        elif lst[i] == "-":
            a = stack.pop()
            b = stack.pop()
            stack.push(b - a)
        elif lst[i] == "*":
            a = stack.pop()
            b = stack.pop()
            stack.push(a * b)
        elif lst[i] == "/" and stack.stack[-1] != 0:
            a = stack.pop()
            b = stack.pop()
            stack.push(b / a)
        else:
            stack.push(int(lst[i]))
    print(stack.stack[-1])

lst = list(map(str, input().split()))
Reverse_polish(lst)

Submission status: Accepted

Solution code:
nlist=[]
command=input().split()

for c in command:
    if c=="+":
        ans=int(nlist[-1])+int(nlist[-2])
        nlist.pop(-1)
        nlist.pop(-1)
        nlist.append(ans)

    elif c=="-":
        ans=int(nlist[-2])-int(nlist[-1])
        nlist.pop(-1)
        nlist.pop(-1)
        nlist.append(ans)

    elif c=="*":
        ans=int(nlist[-2])*int(nlist[-1])
        nlist.pop(-1)
        nlist.pop(-1)
        nlist.append(ans)

    else:
        nlist.append(c)

print(nlist[0])

Submission status: Accepted

Solution code:
from sys import stdin
from operator import add,sub,mul

stack = list()
for i in stdin.readline().split():
    if str.isdecimal(i):
        stack.append(int(i))
    else:
        operation = None
        if i == "+":
            operation = add
        elif i == "-":
            operation = sub
        elif i == "*":
            operation = mul
        operand2 = stack.pop()
        operand1 = stack.pop()
        stack.append(operation(operand1, operand2))

print(stack.pop())

Submission status: Accepted

Solution code:
poland = input().split()
n = len(poland)
stack = []
for i in range(n):
    if poland[i] == "+":
        stack.append(stack.pop(-2) + stack.pop(-1))
    elif poland[i] == "-":
        stack.append(stack.pop(-2) - stack.pop(-1))
    elif poland[i] == "*":
        stack.append(stack.pop(-2) * stack.pop(-1))
    else:
        stack.append(int(poland[i]))

print(str(stack[-1]))

Submission status: Accepted

Solution code:
inp = list(input().split())
stk = []
for i in range(len(inp)):
    if inp[i]!='+' and  inp[i]!='-' and inp[i]!='*':
        stk.append(int(inp[i]))
    else:
        if inp[i] == '+':
            up = stk.pop(-1)
            down = stk.pop(-1)
            stk.append(down + up)
        elif inp[i] == '-':
            up = stk.pop(-1)
            down = stk.pop(-1)
            stk.append(down - up)
        else:
            up = stk.pop(-1)
            down = stk.pop(-1)
            stk.append(down * up)
print(stk[0])

Submission status: Accepted

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

for x in INPUT:
    if x.isdigit():
        stack.append(x)
    else:
        second_item = stack.pop()
        first_item = stack.pop()
        tmp = eval(first_item + x + second_item)
        stack.append(str(tmp))

print(int(stack.pop()))

Submission status: Accepted

Solution code:
import re

A = input().split()

stack = []

for s in A:
    if re.match("[0-9]+", s):
        stack.append(int(s))
    elif re.match("\+", s):
        stack.append(stack.pop(-2) + stack.pop(-1))
    elif re.match("-", s):
        stack.append(stack.pop(-2) - stack.pop(-1))
    elif re.match("\*", s):
        stack.append(stack.pop(-2) * stack.pop(-1))

print(stack[0])

Submission status: Accepted

Solution code:
P = input().split()
stack = []
for p in P:
    if p == '+' or p == '-' or p == '*':
        a, b = stack.pop(), stack.pop()
        if p == '+':
            stack.append(b+a)
        elif p == '-':
            stack.append(b-a)
        else:
            stack.append(b*a)
    else:
        stack.append(int(p))
print(stack.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
E=list(map(str,input().split()))
S=[]

for e in E:
    try:
        S.append(int(e))
    except ValueError:
        if e=='+':
            S[-2]=S[-2]+S[-1]
            S.pop(-1)
        elif e=='-':
            S[-2]=S[-2]-S[-1]
            S.pop(-1)
        elif e=='*':
            S[-2]=S[-2]*S[-1]
            S.pop(-1)
print(*S)

Submission status: Accepted

Solution code:
s = input().split()
stack = []
for ch in s:
    if ch in '+-*':
        b = stack[-1]
        stack.pop()
        a = stack[-1]
        stack.pop()
        stack.append(str(eval(a + ch + b)))
    else:
        stack.append(ch)
print(int(stack[-1]))

Submission status: Accepted

Solution code:
stack = []
for s in input().split():
    if s.isdecimal():
        stack.append(int(s))
    else:
        a = stack.pop()
        b = stack.pop()
        stack.append(eval(str(b) + s + str(a)))

print(stack[0])

Submission status: Accepted

Solution code:
from collections import deque
s = map(str,input().split())
stack = deque([])
for i in s:
    if i == "+" or i == "-" or i == "*":
        stack.append(i)
    else:
        stack.append(int(i))
ans = deque([])
while stack:
    p = stack.popleft()
    if p == "+":
        p_1 = ans.pop()
        p_2 = ans.pop()
        ans.append(p_1+p_2)
    elif p == "*":
        p_1 = ans.pop()
        p_2 = ans.pop()
        ans.append(p_1*p_2)
    elif p == "-":
        p_1 = ans.pop()
        p_2 = ans.pop()
        ans.append(p_2 - p_1)
    else:
        ans.append(p)
print(*ans)

Submission status: Accepted

Solution code:
class mystack:
    def __init__(self, stack):
        self.max = 200
        self.stack = [stack for _ in range(self.max)]
        self.top = 0

    def init(self):
        self.top = 0

    def push(self, arg):
        self.top += 1
        self.stack[self.top] = arg

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


inputs = list(input().split())

stack = mystack([])

for i in inputs:
    if i == "+":
        a = stack.pop()
        b = stack.pop()
        stack.push(b + a)
    elif i == "-":
        a = stack.pop()
        b = stack.pop()
        stack.push(b - a)
    elif i == "*":
        a = stack.pop()
        b = stack.pop()
        stack.push(b * a)
    else:
        i = int(i)
        stack.push(i)

print(stack.pop())

Submission status: Accepted

Solution code:
A = list(input().split())

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

stack = []

for v in A:
	if v not in op:
		stack.append(v)
	elif v in op:
		tmp1 = int(stack.pop())
		tmp2 = int(stack.pop())
		if v == '+':
			stack.append(tmp2 + tmp1)
		elif v == '-':
			stack.append(tmp2 - tmp1)
		elif v == '*':
			stack.append(tmp2 * tmp1)

print(stack[0])

Submission status: Accepted

Solution code:
class Stack():
    def __init__(self, max_size = 10):
        self.top = 0
        self.max = max_size
        self.s = [None for _ in range(self.max)]
    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top >= self.max - 1

    def push(self, x):
        if self.is_full():
            print('Error: Stack Overflow')
        self.top += 1
        self.s[self.top] = x

    def pop(self):
        if self.is_empty():
            print('Error: Stack Underflow')
        self.top -= 1
        return self.s[self.top + 1]


line = input().split()
stack = Stack(len(line))

for i in line:
    try:
        i = int(i)
    except:
        i = str(i)

    if type(i) == int:
        stack.push(i)
    else:
        num2 = stack.pop()
        num1 = stack.pop()
        if i == '+':
            stack.push(num1 + num2)
        elif i == '-':
            stack.push(num1 - num2)
        elif i == '*':
            stack.push(num1 * num2)

print(stack.pop())

Submission status: Accepted

Solution code:
from collections import deque

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

for i in range(len(input_str)):
  ch = input_str[i]
  if ch in ['+', '-', '*']:
    num1 = dq.pop()
    num2 = dq.pop()
    num = 0
    if ch == '+':
      num = num2 + num1
    if ch == '-':
      num = num2 - num1
    if ch == '*':
      num = num2 * num1
    dq.append(num)
  else:
    dq.append(int(ch))

print(dq[0])

Submission status: Accepted

Solution code:
L = list(input().split(' '))
s = []

for l in L:
    if l == '+':
        a = s.pop()
        b = s.pop()
        s.append(a + b)
    elif l == '-':
        a = s.pop()
        b = s.pop()
        s.append(b - a)
    elif l == '*':
        a = s.pop()
        b = s.pop()
        s.append(a * b)
    else:
        s.append(int(l))
print(s[0])

Submission status: Accepted

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

st = []

for i in a:
    if i in '+-*':
        b = st.pop()
        a = st.pop()
        st.append(str(eval(a + i + b)))
    else:
        st.append(i)
print(st[0])

Submission status: Accepted

Solution code:
# スタック

a = input().split(" ")
stack = []

for x in a:
    if x == "+":
        a1 = stack.pop()
        a2 = stack.pop()
        a3 = a2 + a1
        stack.append(a3)
    elif x == "-":
        a1 = stack.pop()
        a2 = stack.pop()
        a3 = a2 - a1
        stack.append(a3)
    elif x == "*":
        a1 = stack.pop()
        a2 = stack.pop()
        a3 = a2 * a1
        stack.append(a3)
    elif x == "/":
        a1 = stack.pop()
        a2 = stack.pop()
        a3 = a2 / a1
        stack.append(a3)
    else:
        stack.append(int(x))

print(stack[0])

Submission status: Accepted

Solution code:
# -*- coding:utf8 -*-

l = list(map(str, input().split()))
s = []

def add(x, y):
    return x + y

def sub(x, y):
    return x - y

def mul(x, y):
    return x * y

for item in l:
    v = None
    if item == '+':
        v = add(s.pop(-1), s.pop(-1))
    elif item == '-':
        v = sub(s.pop(-2), s.pop(-1))
    elif item == '*':
        v = mul(s.pop(-1), s.pop(-1))
    else:
        v = int(item)
    s.append(v)
print(s[0])

Submission status: Accepted

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

for i in S:
    if i in ["+","-","*","/"]:
        a = ans.pop()
        b = ans.pop()
        ans.append(eval("b"+i+"a"))
    else:
        ans.append(int(i))

print(ans[0])

Submission status: Accepted

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

for op in ops:
    if op == '+':
        op2 = stack.pop()
        op1 = stack.pop()
        stack.append(op1 + op2)
    elif op == '-':
        # ['3', '4', '-'] should be '-1'
        op2 = stack.pop()
        op1 = stack.pop()
        stack.append(op1 - op2)
    elif op == '*':
        op2 = stack.pop()
        op1 = stack.pop()
        stack.append(op1 * op2)
    else:
        stack.append(int(op))

print(stack.pop())

Submission status: Accepted

Solution code:
from collections import deque

stack = deque()

for i in input().split():
    if not i in ['+','-','*']:
        stack.append(int(i))
    else:
        num1 = stack.pop()
        num2 = stack.pop()
        if i == "+":
            num = num1+num2
        elif i=="-":
            num = num2-num1
        else:
            num = num1*num2
        stack.append(num)

print(stack[0])

Submission status: Accepted

Solution code:
from collections import deque
formula=input().split()
N=len(formula)

q=deque()
i=0

def calculation(operand):
    a=q.pop()
    b=q.pop()
    q.append(str(eval("".join([b,operand,a]))))

while i < N:
    char=formula[i]
    if char=="+" or char=="-" or char == "*":
        calculation(char)
    else:
        q.append(char)
    i += 1

print(q.pop())

Submission status: Accepted

Solution code:
problem = [x for x in input().split()]

nums = []
for x in problem:
    if x.isnumeric():
        nums.append(int(x))
    else:
        if x == '+':
            a = nums.pop()
            b = nums.pop()
            nums.append(a + b)
        elif x == '-':
            a = nums.pop()
            b = nums.pop()
            nums.append(b - a)
        elif x == '*':
            a = nums.pop()
            b = nums.pop()
            nums.append(a * b)

print(nums[0])

Submission status: Accepted

Solution code:
L = list(input().split())
a = []

for i in L:
	if i in ["+","-","*"]:
		c,b = str(a.pop()), str(a.pop())
		b += i + c
		a += [int(eval(b))]
	else:
		a += [int(i)]

print(a.pop())

Submission status: Accepted

Solution code:
# ALDS1_3_A: Stack

#A = '1 2 + 3 4 - *'.split()
#A = '1 2 +'.split()
#A = '34 116 + 20 5 - 5 - 1 * +'.split()

A = input().split()

B = []
for v in A:
    if v in '+-*':
        o1 = B.pop()
        o2 = B.pop()
        if v == '+':
            B.append(o2 + o1)
        elif v == '-':
            B.append(o2 - o1)
        elif v == '*':
            B.append(o2 * o1)
    else:
            B.append(int(v))
    #print(B)
print(B[0])

Submission status: Accepted

Solution code:
import queue

S = list(input().split())
stack = queue.LifoQueue()

for i in range(len(S)):
  if S[i] != "+" and S[i] != "-" and S[i] != "*":
    S[i] = int(S[i])
    stack.put(S[i])
  else:
    x = stack.get()
    y = stack.get()
    if S[i] == "+":
      stack.put(y + x)
    elif S[i] == "-":
      stack.put(y - x)
    elif S[i] == "*":
      stack.put(y * x)

print(stack.get())

Submission status: Accepted

Solution code:
n = list(map(str,input().split()))
stack = []
for i in n:
    if i.isnumeric():
        stack.append(i)
    else:
        x_1 = stack.pop()
        x_2 = stack.pop()
        tmp = eval(x_2 + i + x_1)
        stack.append(str(tmp))
else:
    print(stack.pop())

Submission status: Accepted

Solution code:
s = []
for x in input().split():
    if x == "+":
        b = s.pop()
        a = s.pop()
        s.append(a+b)
    elif x == "-":
        b = s.pop()
        a = s.pop()
        s.append(a-b)
    elif x == "*":
        b = s.pop()
        a = s.pop()
        s.append(a*b)
    else:
        s.append(int(x))
print(s.pop())

Submission status: Accepted

Solution code:
from collections import deque
#S = deque(['x', 'y'])
#print(S)   ->   deque(['x', 'y'])
#popleft  ->  キュー
#pop  ->  スタック

stack = deque()

l = list(input().split())
for i in l:
    if i!='+' and i!='-' and i!='*':
        stack.append(int(i))
    else:
        b = stack.pop()
        a = stack.pop()
        if i=='+':
            stack.append(a+b)
        elif i=='-':
            stack.append(a-b)
        else:
            stack.append(a*b)
print(stack.pop())

Submission status: Accepted

Solution code:
def cal(operand,a,b):
  if operand == "+":
    return int(a)+int(b)

  elif operand == "-":
    return int(a)-int(b)

  elif operand == "*":
    return int(a)*int(b)

por=[]

por = list(input().split())

stk=[]

for i in por:
  if i.isdigit() == True:
    stk.append(int(i))

  else:
    b=stk.pop()
    a=stk.pop()
    stk.append(cal(i,a,b))

print(stk[0])

Submission status: Accepted

Solution code:
s = input().split()
stack = []
for op in s:
    if op == "+":
        i1 = stack.pop()
        i2 = stack.pop()
        stack.append(i1+i2)
    elif op == "-":
        i1 = stack.pop()
        i2 = stack.pop()
        stack.append(i2-i1)
    elif op == "*":
        i1 = stack.pop()
        i2 = stack.pop()
        stack.append(i2*i1)
    else:
        stack.append(int(op))
print(*stack)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
stack = []

for s in input().split():
  if s in '+-*':
    res = 0
    b = stack.pop(-1)
    a = stack.pop(-1)
  
    if s == '+': 
      res = a + b
    elif s == '-':
      res = a - b
    elif s == '*':
      res = a * b
  
    stack.append(res)
  else:
    stack.append(int(s))

print(stack[0])

Submission status: Accepted

Solution code:
class Stack():
    def __init__(self):
        self.top=0
        self.S=[None]*1000
    def isEmpty(self):
        return self.top==0
    def push(self,fig):

        if fig.isdigit():
            self.top += 1
            self.S.insert(self.top,fig)
        else:#ここで代入したものが記号なら
            before,after = self.pop(),self.pop()
            result = eval(str(after)+fig+str(before))
            self.top += 1
            self.S.insert(self.top, result)
    def pop(self):
        self.top-=1
        vari=self.S[self.top + 1]
        self.S[self.top + 1]=None
        return vari

Stck=Stack()

# math=[int(x) if x.isdigit() else x for x in input().split()]#ここに入る内容を一つずつ処理
[Stck.push(x) for x in input().split()]
print(Stck.S[1])