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: Wrong Answer

Solution code:
a = input().split()
b = []
for i in a:
    if i.isdigit():
        b.append(i)
    else:
        c = b.pop()
        d = b.pop()
        ans = eval(str(d)+i+str(c))
        b.append(ans)
print(b)

Submission status: Wrong Answer

Solution code:
def add(a,b): 
    return a + b
def sub(a,b): 
    return a - b
def mul(a,b): 
    return a * b
def div(a,b): 
    return a/ float(b)

A=input().split()
i=0
for j in range(len(A)):
    print(i)
    if A[i]=="+":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=add(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    if A[i]=="-":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=sub(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    if A[i]=="*":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=mul(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    if A[i]=="/":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=div(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    i=i+1
print(r)

Submission status: Wrong Answer

Solution code:
def cal(ope,a,b):
    if ope=="+":
        x=a+b
    elif ope=="-":
        x=a-b
    elif ope=="*":
        x=a*b
    return x

lst=input().split()
stack=[]
for i in range(len(lst)):
    if lst[i]=="+" or lst[i]=="-" or lst[i]=="*": pass
    else:
        lst[i]=int(lst[i])
for i in range(len(lst)):
    if lst[i]=="+" or lst[i]=="-" or lst[i]=="*": 
        a=stack.pop()
        b=stack.pop()
        c=cal(lst[i],a,b)
        stack.append(c)
    else:
        stack.append(lst[i])
print(stack[0])

Submission status: Wrong Answer

Solution code:
def cal(ope,a,b):
    if ope=="+":
        x=a+b
    elif ope=="-":
        x=a-b
    elif ope=="*":
        x=a*b
    return x

lst=input().split()
stack=[]
for i in range(len(lst)):
    if lst[i]=="+" or lst[i]=="-" or lst[i]=="*": pass
    else:
        lst[i]=int(lst[i])
for i in range(len(lst)):
    if lst[i]=="+" or lst[i]=="-" or lst[i]=="*": 
        a=stack.pop()
        b=stack.pop()
        c=cal(lst[i],b,a)
        print(c)
        stack.append(c)
    else:
        stack.append(lst[i])
print(stack[0])

Submission status: Wrong Answer

Solution code:
import sys
a = list(input().split())
stack = []
for i in range(len(a)):
    n = len(stack)
    if a[i] == '+':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp = int(stack.pop(n-1)) + int(stack.pop(n-2))
        stack.append(tmp)
        
    elif a[i] == '-':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp_1 = int(stack.pop(n-1))
        tmp_2 = int(stack.pop(n-2))
        tmp = tmp_2 - tmp_1
        stack.append(tmp)
        
    elif a[i] == '*':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp = int(stack.pop(n-1)) * int(stack.pop(n-2))
        stack.append(tmp)
        
    elif a[i] == '/':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp_1 = int(stack.pop(n-1))
        tmp_2 = int(stack.pop(n-2))
        tmp = tmp_2 / tmp_1
        stack.append(tmp)
    else:
        stack.append(int(a[i]))

Submission status: Wrong Answer

Solution code:
def kei(a,i,stac,ind):
	if a[i]=="+":
		stac[ind-2]=stac[ind-1]+stac[ind-2]
		#print("+")
	elif a[i]=="-":
		stac[ind-2]=stac[ind-1]-stac[ind-2]
		#print("-")
	elif a[i]=="*":
		stac[ind-2]=stac[ind-1]*stac[ind-2]
		#print("*") 
	return stac[ind-2]


a=[]
stac=[]
a=list(input().split())
ind=0
for i in range(len(a)):
	if a[i].isdigit():
		stac.append(int(a[i]))
		#stac=int(stac[ind])
		ind+=1
		#print(stac)
	else:
		stac[ind-2]=kei(a,i,stac,ind)
		ind-=1
		
print(stac[0])

Submission status: Wrong Answer

Solution code:
def kei(a,i,stac,ind):
	if a[i]=="+":
		stac[ind-2]=stac[ind-1]+stac[ind-2]
		#print("+")
	elif a[i]=="-":
		stac[ind-2]=stac[ind-1]-stac[ind-2]
		#print("-")
	elif a[i]=="*":
		stac[ind-2]=stac[ind-1]*stac[ind-2]
		#print("*") 
	return stac[ind-2]


a=[]
stac=[]
a=list(input().split())
ind=0
for i in range(len(a)):
	if a[i].isdigit():
		stac.append(int(a[i]))
		#stac=int(stac[ind])
		ind+=1
		#print(stac)
	else:
		stac[ind-2]=kei(a,i,stac,ind)
		stac.pop()

		ind-=1
		
print(stac[0])

Submission status: Wrong Answer

Solution code:
def kei(a,i,x,y):
	if a[i]=="+":
		st=x+y
		#print("+")
	elif a[i]=="-":
		st=x-y
		#print("-")
	elif a[i]=="*":
		st=x*y
		#print("*") 
	return st


a=[]
stac=[]
a=list(input().split())
for i in range(len(a)):
	if a[i].isdigit():
		stac.append(int(a[i]))
		#print(stac)
	else:
		x=stac.pop()
		y=stac.pop()
		stac.append(kei(a,i,x,y))
		
print(stac[0])

Submission status: Wrong Answer

Solution code:
def kei(a,i,x,y):
	if a[i]=="+":
		st=x+y
		print("+")
	elif a[i]=="-":
		st=y-x
		print("-")
	elif a[i]=="*":
		st=x*y
		print("*") 
	return st


a=[]
stac=[]
a=list(input().split())
for i in range(len(a)):
	if a[i].isdigit():
		stac.append(int(a[i]))
		#print(stac)
	else:
		x=stac.pop()
		y=stac.pop()
		stac.append(kei(a,i,x,y))
		
print(stac[0])

Submission status: Wrong Answer

Solution code:
l=list(input().split())  ##文字も数字も入る
stack=[]

for x in l: ##リストの長さ文だけ繰り返し
    if x in ['+','-','*']: ##←知らなかった判定方法
        t=str(stack.pop()) ##末尾取り出し
        r=str(stack.pop())
        t+=x+r
        stack+=[int(eval(t))] ##eval:入力した式の入力、[]の意味？>リストに追加
    else:
        stack+=[int(x)] ##[]の意味?>リストに追加

print(stack.pop())

Submission status: Wrong Answer

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

for x in l:
    if x in ['+','-','*']: #
        t=str(stack.pop()) 
        r=str(stack.pop())
        t+=x+r
        stack+=[int(eval(t))] 
    else:
        stack+=[int(x)] 

print(stack.pop())

Submission status: Wrong Answer

Solution code:
l=list(input().split())  ##文字も数字も入る
stack=[]

for x in l: ##リストの長さ文だけ繰り返し
    if x in ['+','-','*']: ##←知らなかった判定方法
        t=str(stack.pop()) ##末尾取り出し
        r=str(stack.pop())
        c=r+x+t
        stack+=[int(eval(c))] ##eval:入力した式の入力
        print(stack)
    else:
        stack+=[int(x)] ##[]の意味?>リストに追加
        print(stack)
print(stack.pop())

Submission status: Wrong Answer

Solution code:

def main():
    l = input().split(' ')

    s = []

    for el in l:
        print(s)
        if el in ["+", "-", "*"]:
            a = s.pop(-1)
            b = s.pop(-1)
            s.append(eval(str(b) + el + str(a)))
        else:
            s.append(int(el))

    print(s[0])

main()

Submission status: Wrong Answer

Solution code:
class Stack:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._top = 0

    def push(self, x):
        if self.isFull():
            raise IndexError("stack is full")
        else:
            self._top += 1
            self._l[self._top] = x

    def pop(self):
        if self.isEmpty():
            raise IndexError("pop from empty stack")
        else:
            e = self._l[self._top]
            self._l[self._top] = None
            self._top -= 1
            return e

    def isEmpty(self):
        return self._top == 0

    def isFull(self):
        return self._top == self.n

def poland_calculator(s):
    n = len(s)
    stack = Stack(n)
    i = 0
    while i < n:
        if s[i] == ' ':
            i += 1
            continue
        elif s[i].isdigit():
            sn = ''
            while s[i].isdigit():
                sn += s[i]
                i += 1
                stack.push(int(sn))
        else:
            b = stack.pop()
            a = stack.pop()
            if s[i] == '+':
                e = a + b
            elif s[i] == '-':
                e = a - b
            else:
                e = a * b
            stack.push(e)
            i +=1

    return stack.pop()


if __name__ == '__main__':
    s = input()
    res = poland_calculator(s)
    print(res)

Submission status: Wrong Answer

Solution code:
def RPN(a,b,c,stk):
    if len(stk) == 0:
        stk.append(cul(int(a),int(b),c))
    else:
        if a.isdigit():
            if b.isdigit():
                stk.append(cul(int(a),int(b),c))
            else:
                stk.append(cul(int(stk[0]),int(a),b))
        else:
            stk.append(cul(int(stk[0]),int(stk[1]),a))
    return stk
    

def cul(a,b,operand):
    if operand == "+":
        return a+b
    elif operand == "-":
        return a-b
    elif operand == "*":
        return a*b
    elif operand == "/":
        return a*1.0/b

i = 0
stk = []
li = list(input().split(' '))
while i < len(li)-3:
    temp = len(stk)
    stk = RPN(li[i],li[i+1],li[i+2],stk)
    if len(stk) == temp + 1:
        i = i + 3
    else:
        i = i + 1
    print(stk)
if len(stk) == 2:
    stk[0] = cul(stk[0],stk[1],li[len(li)-1])
if len(li) == 3:
    print(cul(int(li[0]),int(li[1]),li[2]))
else:
    print(stk[0])

Submission status: Wrong Answer

Solution code:
def RPN(a,b,c,stk):
    if len(stk) == 0:
        stk.append(cul(int(a),int(b),c))
    else:
        if a.isdigit():
            if b.isdigit():
                stk.append(cul(int(a),int(b),c))
            else:
                stk.append(cul(int(stk[0]),int(a),b))
        else:
            stk.append(cul(int(stk[0]),int(stk[1]),a))
    return stk
    

def cul(a,b,operand):
    if operand == "+":
        return a+b
    elif operand == "-":
        return a-b
    elif operand == "*":
        return a*b
    elif operand == "/":
        return a*1.0/b

i = 0
stk = []
li = list(input().split(' '))
while i < len(li)-3:
    temp = len(stk)
    stk = RPN(li[i],li[i+1],li[i+2],stk)
    if len(stk) == temp + 1:
        i = i + 3
    else:
        i = i + 1
    print(stk)
if len(stk) == 2:
    stk[0] = cul(stk[0],stk[1],li[len(li)-1])
if len(li) == 3:
    print(cul(int(li[0]),int(li[1]),li[2]))
else:
    print(int(stk[0]))

Submission status: Wrong Answer

Solution code:
def RPN(a,b,c,stk):
    if len(stk) == 0:
        stk.append(cul(int(a),int(b),c))
    else:
        if a.isdigit():
            if b.isdigit():
                stk.append(cul(int(a),int(b),c))
            else:
                stk.append(cul(int(stk[0]),int(a),b))
        else:
            stk.append(cul(int(stk[0]),int(stk[1]),a))
    return stk
    

def cul(a,b,operand):
    if operand == "+":
        return a+b
    elif operand == "-":
        return a-b
    elif operand == "*":
        return a*b
    elif operand == "/":
        return a*1.0/b

i = 0
stk = []
li = list(input().split(' '))
while i < len(li)-3:
    temp = len(stk)
    stk = RPN(li[i],li[i+1],li[i+2],stk)
    if len(stk) == temp + 1:
        i = i + 3
    else:
        i = i + 1
if len(stk) == 2:
    stk[0] = cul(stk[0],stk[1],li[len(li)-1])
if len(li) == 3:
    print(cul(int(li[0]),int(li[1]),li[2]))
else:
    print(int(stk[0]))

Submission status: Wrong Answer

Solution code:
def RPN(a,b,c,stk):
    if len(stk) == 0:
        stk.append(cul(int(a),int(b),c))
    else:
        if a.isdigit():
            if b.isdigit():
                stk.append(cul(int(a),int(b),c))
            else:
                stk = [stk[0],(cul(int(stk[1]),int(a),b))]
        else:
            stk = [(cul(int(stk[0]),int(stk[1]),a))]
    return stk
    

def cul(a,b,operand):
    if operand == "+":
        return a+b
    elif operand == "-":
        return a-b
    elif operand == "*":
        return a*b
    elif operand == "/":
        return a*1.0/b

i = 0
stk = []
li = list(input().split(' '))
while i < len(li)-3:
    temp = len(stk)
    stk = RPN(li[i],li[i+1],li[i+2],stk)
    if len(stk) == temp + 1:
        i = i + 3
    else:
        i = i + 2
    print(stk)
if len(stk) == 2:
    stk[0] = cul(stk[0],stk[1],li[len(li)-1])
if len(li) == 3:
    print(cul(int(li[0]),int(li[1]),li[2]))
else:
    print(int(stk[0]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
line = input().split()
print(line)

Submission status: Wrong Answer

Solution code:
line = input().split()
stack = []
ans = 0
for elem in line:
    if elem in ['+', '-', '*']:
        ele1 = stack.pop()
        ele2 = stack.pop()
        if elem == '+':
            tmp = ele1 + ele2
        if elem == '-':
            tmp = ele1 - ele2
        if elem == '*':
            tmp = ele1 * ele2
        stack.append(tmp)
    else:
        stack.append(elem)
print(stack[0])

Submission status: Wrong Answer

Solution code:
# initialize stack
Stack = []

A = [i for i in input().split()]

for inputData in A:
    if inputData == "+":
        x = Stack.pop()
        y = Stack.pop()
        Stack.append(x+y)

    elif inputData == "-":
        x = Stack.pop()
        y = Stack.pop()
        Stack.append(x-y)

    elif inputData == "*":
        x = Stack.pop()
        y = Stack.pop()
        Stack.append(x*y)

    else:
        Stack.append(int(inputData))
        
print(Stack.pop())

Submission status: Wrong Answer

Solution code:
# initialize stack
Stack = []

A = [i for i in input().split()]

for inputData in A:
    if inputData == "+":
        x = Stack.pop()
        y = Stack.pop()
        Stack.append(x+y)

    elif inputData == "-":
        y = Stack.pop()
        x = Stack.pop()
        Stack.append(x-y)

    elif inputData == "*":
        x = Stack.pop()
        y = Stack.pop()
        Stack.append(x*y)

    else:
        Stack.append(int(inputData))

print(Stack)

Submission status: Wrong Answer

Solution code:
stack = []

for x in input().split():
    if x == '+':
        stack.append(stack.pop()+stack.pop())
    elif x == '-':
        stack.append(stack.pop()-stack.pop())
    elif x == '*':
        stack.append(stack.pop()*stack.pop())
    else:
        stack.append(int(x))

print(stack[0])

Submission status: Wrong Answer

Solution code:
class Stack:
    MAX = 100

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

    def is_empty(self):
        return self.top == 0

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

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

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


arr = [str(s) for s in input().split()]
stack = Stack()
for s in arr:
    if s in ["+", "-", "*", "/"]:
        stack.push(eval(str(stack.pop()) + s + str(stack.pop())))
    else:
        stack.push(int(s))

print(stack.pop())

Submission status: Wrong Answer

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

    def is_empty(self):
        return self.top == 0

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

    def push(self, x):
        self.top += 1
        self.S[self.top] = x
        return x

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


stack = Stack()
print([stack.push(eval("".join(map(str,[stack.pop(),s,stack.pop()][::-1]))))
 if s in["+","-","*"]else stack.push(int(s))for s in input().split()][0])

Submission status: Wrong Answer

Solution code:
inp = map(str, raw_input().split())
s = []
for i in inp:
    if   i == "+": s.append( s.pop(-2) + s.pop(-1) )
    elif i == "-": s.append( s.pop(-2) - s.pop(-1) )
    elif i == "*": s.append( s.pop(-2) * s.pop(-1) )
    elif i == "/": s.append( s.pop(-2) / s.pop(-1) )
    else: s.append(float(i))
print s[0]

Submission status: Time Limit Exceeded

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

def keisan(inputEnzan):
    while True:
        stockFornumber=[]
        index=0
        length=len(inputEnzan)
        if length==1:
            break
        while index<length:
            if inputEnzan[index]=="+" or inputEnzan[index]=="-" or inputEnzan[index]=="*":
                if len(stockFornumber)==2:
                    if inputEnzan[index]=="+":
                        inputEnzan[index]=stockFornumber[0]+stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"

                    elif inputEnzan[index]=="-":
                        inputEnzan[index]=stockFornumber[0]-stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"

                    else:
                        inputEnzan[index]=stockFornumber[0]*stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"
                else:
                    pass

            else:
                stockFornumber.append(int(inputEnzan[index]))
            index+=1

        while "null" in inputEnzan:
            inputEnzan.remove("null")

    print(inputEnzan[0])

keisan(inputEnzan)

Submission status: Time Limit Exceeded

Solution code:
Sum = input().split()
while ('+' in Sum) or ('-' in Sum) or ('*' in Sum) :
    for che in 2, 3 :
        if Sum[che] == '+' : 
            Sum.insert((che - 2), (int(Sum.pop(che - 2)) + int(Sum.pop(che - 2))))
            del Sum[che - 1]
        elif Sum[che] == '-' :
            Sum.insert((che - 2), (int(Sum.pop(che - 2)) - int(Sum.pop(che - 2))))
            del Sum[che - 1]
        elif Sum[2] == '*' : 
            Sum.insert((che - 2), (int(Sum.pop(che - 2)) * int(Sum.pop(che - 2))))
            del Sum[che - 1]
        if ('+' not in Sum) and ('-' not in Sum) and ('*' not in Sum) : break
print(Sum[0])

Submission status: Time Limit Exceeded

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

def mak(che) :
    if Sum[che] == '+' : 
        Sum.insert((che - 2), (int(Sum.pop(che - 2)) + int(Sum.pop(che - 2))))
        del Sum[che - 1]
    elif Sum[che] == '-' :
        Sum.insert((che - 2), (int(Sum.pop(che - 2)) - int(Sum.pop(che - 2))))
        del Sum[che - 1]
    elif Sum[che] == '*' : 
        Sum.insert((che - 2), (int(Sum.pop(che - 2)) * int(Sum.pop(che - 2))))
        del Sum[che - 1]
    

while ('+' in Sum) or ('-' in Sum) or ('*' in Sum) :
    for che in 2, 3 :
        mak(che)
        if len(Sum) == 3 : break
        if ('+' not in Sum) and ('-' not in Sum) and ('*' not in Sum) : break
    
print(Sum[0])

Submission status: Accepted

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

def keisan(inputEnzan):
    while True:
        stockFornumber=[]
        index=0
        length=len(inputEnzan)
        if length==1:
            break
        while index<length:
            if inputEnzan[index]=="+" or inputEnzan[index]=="-" or inputEnzan[index]=="*":
                if len(stockFornumber)==2:
                    if inputEnzan[index]=="+":
                        inputEnzan[index]=stockFornumber[0]+stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"

                    elif inputEnzan[index]=="-":
                        inputEnzan[index]=stockFornumber[0]-stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"

                    else:
                        inputEnzan[index]=stockFornumber[0]*stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"
                else:
                    stockFornumber=[]
                    pass

            else:
                if len(stockFornumber)==2:
                    del stockFornumber[0]
                stockFornumber.append(int(inputEnzan[index]))
                    
            index+=1

        while "null" in inputEnzan:
            inputEnzan.remove("null")

    print(inputEnzan[0])

keisan(inputEnzan)

Submission status: Accepted

Solution code:
arr = input().split()
stack = list()
for el in arr:
    if el.isdigit():
        stack.append(int(el))
        continue
    elif el == "*":
        stack.append(stack.pop() * stack.pop())
        continue
    elif el == "+":
        stack.append(stack.pop() + stack.pop())
        continue
    elif el == "-":
        stack.append(-stack.pop() + stack.pop())
        continue
print(stack.pop())

Submission status: Accepted

Solution code:
exp  = input().split()
stk = []

for i in exp :
    if i in ('+', '-', '*') :
        num1 = stk.pop()
        num2 = stk.pop()
        
        if i == '+' :
            stk.append(str(int(num1) + int(num2)))
        elif i == '-' :
            stk.append(str(int(num2) - int(num1)))
        else :
            stk.append(str(int(num2) * int(num1)))            
    else :
        stk.append(i)
        
print(stk.pop())

Submission status: Accepted

Solution code:
def main():
    N = [x for x in input().split(' ')]
    #データを格納するための整数型1次元配列
    stack = []
    for i in N:
        # +が入っていた場合
        if i == '+':
            num1 = stack.pop()
            num2 = stack.pop()
            stack.append(num1 + num2)
        # -が入っていた場合
        elif i == '-':
            num2 = stack.pop()
            num1 = stack.pop()
            stack.append(num1 - num2)
        # *が入っていた場合
        elif i == '*':
            num1 = stack.pop()
            num2 = stack.pop()
            stack.append(num1 * num2)
        #算術演算子( + - *)以外が入っていた場合
        else:
            stack.append(int(i))
            
    #表示
    print(stack.pop())
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: UTF-8 -*-
# Stack

top = 0
S = {}

def push(x):
    global top
    global S
    top += 1
    S[top] = x

def pop():
    global top
    global S
    top -= 1
    return S[top + 1]

input_list = list(input().split()) #計算対象（スペース区切り→配列に展開）

for target in input_list:
    if target == '+':
        a = pop()
        b = pop()
        c = b+a
        push(c)
    elif target == '-':
        a = pop()
        b = pop()
        c = b-a
        push(c)
    elif target == '*':
        a = pop()
        b = pop()
        c = b*a
        push(c)
    else:
        push(int(target))

print(pop())

Submission status: Accepted

Solution code:
N = [x for x in input().split(' ')]
#データを格納するための整数型1次元配列
stack = []
for i in N:
    # +が入っていた場合
    if i == '+':
        num1 = stack.pop()
        num2 = stack.pop()
        stack.append(num1 + num2)
    # -が入っていた場合
    elif i == '-':
        num2 = stack.pop()
        num1 = stack.pop()
        stack.append(num1 - num2)
    # *が入っていた場合
    elif i == '*':
        num1 = stack.pop()
        num2 = stack.pop()
        stack.append(num1 * num2)
    #算術演算子( + - *)以外が入っていた場合
    else:
        stack.append(int(i))

#表示
print(stack.pop())

Submission status: Accepted

Solution code:
#逆ポーランド記法(Reverse Polish Notation, RPN)
class RPN():
    def __init__(self):
        self.top = 0
        self.S = []
        self.MAX = 100

    def isEmpty(self):
        return self.top == 0

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

    def push(self,x):
        if self.isFull():
            raise ValueError("オーバーフロー")
        self.top+=1
        self.S.append(x)

    def pop(self):
        if self.isEmpty():
            raise ValueError("アンダーフロー")
        self.top-=1
        #print("self.top:{}".format(self.top))
        #print("S:{}".format(self.S))
        return self.S.pop(self.top)


X = input().split(" ")
rpn = RPN()
for x in X:
    #print(x)
    if x.isnumeric():
        #print("num")
        rpn.push(x)
    else:
        #print("dig")
        num_2 =rpn.pop()
        num_1 =rpn.pop()
        res = eval(str(num_1) + x + str(num_2))
        rpn.push(res)

print(rpn.pop())

Submission status: Accepted

Solution code:
def is_operator(ele):
    if ele == "+" or ele == "-" or ele == "*":
        return True
    else:
        return False

def calc_reverse_polish_notation(A):
    stack = []
    for i in A:
        if is_operator(i):
            a = stack.pop()
            b = stack.pop()
            ans = eval("{0} {1} {2}".format(b, i, a))
            stack.append(ans)
        else:
            stack.append(i)
    return stack.pop()

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

print(calc_reverse_polish_notation(A))

Submission status: Accepted

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

def cal_with_operator(b, a, operator):
    return eval('{} {} {}'.format(a, operator, b))

for s in args:
    if s == '+': stack.append(cal_with_operator(stack.pop(), stack.pop(), '+'))
    elif s == '-': stack.append(cal_with_operator(stack.pop(), stack.pop(), '-'))
    elif s == '*': stack.append(cal_with_operator(stack.pop(), stack.pop(), '*'))
    elif s == '/': stack.append(cal_with_operator(stack.pop(), stack.pop(), '/'))
    else : stack.append(s)

print(stack[0])

Submission status: Accepted

Solution code:
def init():
  global top
  top = 0

def isEmpty():
  global top
  return top == 0

def isFull():
  global top, MAX
  return top >= MAX

def push(x):
  global top, s
  if isFull():
    return False
  s[top] = x
  top += 1


def pop():
  global top, s
  if isEmpty():
    return False
  top -= 1
  return s[top]


def calc(i_1, i_2, op):
  if op == '+':
    return i_1 + i_2
  elif op == '-':
    return i_1 - i_2
  else:
    return i_1 * i_2

data = list(map(str, input().split()))
top = 0
MAX = 100
s = [0 for i in range(MAX)]
for i in data:
  if i == '+' or i == '*' or i == '-':
    a = pop()
    b = pop()
    push(calc(int(b), int(a), i))
  else:
    push(i)
print(s[0])

Submission status: Accepted

Solution code:
def init():
  global top
  top = -1

def isEmpty():
  global top
  return top == -1

def isFull():
  global top, MAX
  return top >= MAX

def push(x):
  global top, s
  if isFull():
    return False
  s[top] = x
  top += 1


def pop():
  global top, s
  if isEmpty():
    return False
  top -= 1
  return s[top]


def calc(i_1, i_2, op):
  if op == '+':
    return i_1 + i_2
  elif op == '-':
    return i_1 - i_2
  else:
    return i_1 * i_2

data = list(map(str, input().split()))
top = 0
MAX = 100
s = [0 for i in range(MAX)]
for i in data:
  if i == '+' or i == '*' or i == '-':
    a = pop()
    b = pop()
    push(calc(int(b), int(a), i))
  else:
    push(i)
print(s[0])

Submission status: Accepted

Solution code:

str=raw_input().strip().split()
list=list()


ans=0
for ss in str:
    if ss=="*":
        a=list.pop()
        b=list.pop()
        list.append(a*b)
    elif ss=="+":
        a=list.pop()
        b=list.pop()
        list.append(a+b)

    elif ss=="-":
        a=list.pop()
        b=list.pop()
        list.append(b-a)
        
    else:
        list.append(int(ss))
   
    
print list.pop()

Submission status: Accepted

Solution code:
A = input().split()
stack = []
for s in A:
    if s.isdigit():
        stack.append(int(s))
    else:
        stack.append(eval('{2}{1}{0}'.format(stack.pop(), s, stack.pop())))
print(stack[0])

Submission status: Accepted

Solution code:
n=input().split()
c=0
while len(n)!=1:
	if n[c]=='+':
		n[c-2]=int(n[c-2])+int(n[c-1])
		del n[c-1]
		del n[c-1]
		c=0
	elif n[c]=='-':
		n[c-2]=int(n[c-2])-int(n[c-1])
		del n[c-1]
		del n[c-1]
		c=0
	elif n[c]=='*':
		n[c-2]=int(n[c-2])*int(n[c-1])
		del n[c-1]
		del n[c-1]
		c=0
	elif n[c]=='/':
		n[c-2]=int(n[c-2])/int(n[c-1])
		del n[c-1]
		del n[c-1]
		c=0
	c+=1
a=int(n[0])
print(a)

Submission status: Accepted

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

for op in f:
    if op in '+-*':
        b = stack.pop()
        a = stack.pop()
        stack.append(str(eval(a+op+b)))
    else:
        stack.append(op)

print(''.join(stack))

Submission status: Accepted

Solution code:
def main():
    stack = []
    for char in input().split():
        if char in ['+', '-', '*']:
            right = int(stack.pop())
            left = int(stack.pop())
            if char == '+':
                c = left + right
            elif char == '-':
                c = left - right
            elif char == '*':
                c = left * right
            else:
                raise AssertionError
            stack.append(c)
        else:
            stack.append(int(char))

    print(stack[0])
    return


main()

Submission status: Accepted

Solution code:
stack = []

for op in input().split():
    if op in '+-*':
        b = stack.pop()
        a = stack.pop()
        stack.append(str(eval(a+op+b)))
    else:
        stack.append(op)

print(''.join(stack))

Submission status: Accepted

Solution code:
A = list(map(str,input().split()))
stack = []
for item in A:
    if item != '+' and item != '-' and item != '*':
        stack.append(str(item))
    elif item == '+':
        v = int(stack[-2]) + int(stack[-1])
        del stack[-2]
        del stack[-1]
        stack.append(str(v))
    elif item == '-':
        v = int(stack[-2]) - int(stack[-1])
        del stack[-2]
        del stack[-1]
        stack.append(str(v))
    elif item == '*':
        v = int(stack[-2]) * int(stack[-1])
        del stack[-2]
        del stack[-1]
        stack.append(str(v))

print(stack[-1])

Submission status: Accepted

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

Submission status: Accepted

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

stack = []
for n in inl:
    if n == '+':
        stack.append(stack.pop() + stack.pop())
    elif n == '-':
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif n == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(n))
print(stack.pop())