Problem:


Smart Calculator

Your task is to write a program which reads an expression and evaluates it.

The expression consists of numerical values, operators and parentheses, and the ends with '='.

The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.

 Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.

You may assume that there is no division by zero.

All calculation is performed as integers, and after the decimal point should be truncated

Length of the expression will not exceed 100.

-1 &times 109 ≤ intermediate results of computation ≤ 109

Input

The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.

Output

For each datasets, prints the result of calculation.

Sample Input

2
4-2*3=
4*(8+4+3)=

Output for the Sample Input

-2
60



Sample input:
2
4-2*3=
4*(8+4+3)=


Sample output:
-2
60

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    s=input()
    print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    print(input())

Submission status: Wrong Answer

Solution code:
n=int(input())
s=""
for i in range(n):
    s=raw_input()
    print(eval(s[0:-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=""
for i in range(n):
    s=input()
    print(eval(s[0:-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    s=input()
    print(int(eval(s[0:-1])))

Submission status: Wrong Answer

Solution code:
n=int(input())
for _ in range(n):
    s=input()
    s=s.replace("/","//")
    s=s[:-1:]
    print(eval(s))

Submission status: Wrong Answer

Solution code:
for i in range( int(raw_input()) ): print eval( raw_input()[:-1] )

Submission status: Wrong Answer

Solution code:
for _ in range( int(raw_input()) ): print int(eval( "1.0+"+raw_input()[:-1] ))

Submission status: Wrong Answer

Solution code:
for _ in range( int(raw_input()) ): print int(eval( "1.0*"+raw_input()[:-1] ))

Submission status: Wrong Answer

Solution code:
while True:
    try:
        for i in range(int(input())):
            print(str(int(eval(input().replace('=', '')))))
    except:
        break

Submission status: Wrong Answer

Solution code:
# Edit: 2014/09/26
# Lang: Python3
# Time: 0.xxs
#

if __name__ == "__main__":
    n = int(input())
    for i in range(n):
        print(eval(input().strip("=").replace("/","//")))

Submission status: Wrong Answer

Solution code:
# Edit: 2014/09/26
# Lang: Python3
# Time: 0.xxs
#

if __name__ == "__main__":
    n = int(input())
    for i in range(n):
        print(eval(input().strip("=").replace("/", "//")))

Submission status: Wrong Answer

Solution code:
n=input()
for _ in [0]*n: 
  print eval(raw_input()[:-1])

Submission status: Wrong Answer

Solution code:
def f(s):
  while 1:
    b=s.find(")")
    if b<0: return g(s)
    a=s[:b].rfind("(")
    s1=s[a:b+1]
    s=s.replace(s1,f(s1[1:-1]))

def g(s):
  a=""
  f=1
  x=[]
  def F(a,b):
    x.append(a)
    x.append(b)
    return 1,""
  for c in s:
    if c=="=": continue
    elif c in "*/": f,a=F(a,c)
    elif c in "+-":
      if f==1: f,a=0,c
      else: f,a=F(a,c)
    else: f,a=0,a+c
  x.append(a)

  s=x[:]
  x=[]
  f=""
  for e in s:
    if e in "+-": x.append(e)
    elif e in "*/": f=e
    else:
      a=int(e)
      if f=="*": a*=x.pop()
      elif f=="/": a=x.pop()/a
      x.append(a)
      f=""

  s=x[:]
  x=[]
  f=""
  for e in s:
    if e=="+" or e=="-": f=e
    else:
      a=int(e)
      if f=="+": a+=x.pop()
      elif f=="-": a=x.pop()-a
      x.append(a)
      f=""
  return str(x[0])

n=input()
for _ in [0]*n: 
  s=raw_input()
  print f(s)

Submission status: Wrong Answer

Solution code:
def f(s):
  while 1:
    b=s.find(")")
    if b<0: return g(s)
    a=s[:b].rfind("(")
    s=s.replace(s[a:b+1],f(s[a+1:b]))

def g(s):
  a=""
  f=1
  x=[]
  def F(a,b):
    x.append(a)
    x.append(b)
    return 1,""
  for c in s:
    if c=="=": continue
    elif c in "*/": f,a=F(a,c)
    elif c in "+-":
      if f==1: f,a=0,c
      else: f,a=F(a,c)
    else: f,a=0,a+c
  x.append(a)

  s=x[:]
  x=[]
  f=""
  for e in s:
    if e in "+-": x.append(e)
    elif e in "*/": f=e
    else:
      a=int(e)
      if f=="*": a*=x.pop()
      elif f=="/": a=int(1.0*x.pop()/a)
      x.append(a)
      f=""

  a,f=0,1
  for e in x:
    if e=="+": f=1
    elif e=="-": f=-1
    else: a+=f*e
  return str(a)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
while n != 0:
	s = input()
	print(eval(s[0:len(s)-1]));
	n -= 1
	sys.stdout.flush()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

n = int(input())

for _ in range(n):
    print(eval(input()[0:-1]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

import re
n = int(input())
for _ in range(n):
    print(eval(re.sub(r'(\d+/\d+)', r'int(\1)', input()[0:-1])))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

import re
n = int(input())
for _ in range(n):
    print(int(eval(re.sub(r'(\d+/\d+)', r'int(\1)', input()[0:-1]))))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

import re
n = int(input())
for _ in range(n):
    expr = input()[0:-1]
    expr = expr.replace('/', '//');
    print(eval(expr))

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
for loop in xrange(N):
    print eval(raw_input()[:-1].replace("/","//"))

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
for loop in xrange(N):
    print eval(raw_input()[:-1])

Submission status: Wrong Answer

Solution code:
for i in xrange(int(raw_input())):
	s = raw_input()
	print eval(s[:-1])

Submission status: Wrong Answer

Solution code:
n = input()
for i in range(n):
    print eval(raw_input().strip("="))

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):print(eval(input()[:-1]))

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):print(eval(input()[:-1].replace('/', '//')))

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):print(int(eval(input()[:-1])))

Submission status: Wrong Answer

Solution code:
for _ in range(input()):print(eval(raw_input()[:-1]))

Submission status: Wrong Answer

Solution code:
def up_to_you(formula):
    l_p = None
    r_p = None
    for i, c in enumerate(formula):
        if c == '(':
            l_p = i
        elif c == ')':
            r_p = i
            break
    else:
        print fx(formula)
        return
    
    r = fx(formula[l_p+1:r_p])
    n_formula = formula[:l_p]+r+formula[r_p+1:]
    return up_to_you(n_formula)
            
def fx(gemstone):
    n = ''
    lis = []
    add = ''
    if gemstone[0] == '-':
        gemstone = gemstone[1:]
        add = '-'
    for c in gemstone:
        if c.isdigit():
            n += c
        else:
            if n == '':
                add = '-'
            else:
                lis.append(add+n)
                lis.append(c)
                n = ''
                add = ''
    else:
        lis.append(add+n)
    return isolation(lis)
    
def isolation(lis):
    if len(lis) == 1:
        return str(lis[0])
    o1 = None
    o = None
    o2 = None
    o_i = None
    n_lis = None
    if '*' in lis or '/' in lis:
        for i, v in enumerate(lis):
            if o1 == None:
                o1 = v
            elif v == '*' or v == '/':
                o = v
                o_i = i
            elif v == '+' or v == '-':
                o1 = None
            else:
                o2 = v
                r = discomfort(int(o1), o, int(o2))
                n_lis = lis[:(o_i-1)]+[r]+lis[(o_i+2):]
                return isolation(n_lis)
    else:
        o1 = lis[0]
        o = lis[1]
        o2 = lis[2]
        o_i = 1
        r = discomfort(int(o1), o, int(o2))
        n_lis = lis[:(o_i-1)]+[r]+lis[(o_i+2):]
        return isolation(n_lis)
                
def discomfort(o1, o, o2):
    r = None
    if o == '*':
        r = o1 * o2
    elif o == '/':
        r = o1 / o2
        if o1 < 0: r += 1
    elif o == '+':
        r = o1 + o2
    elif o == '-':
        r = o1 - o2
    return str(r)
    
if __name__ == '__main__':
    N = int(raw_input())
    for i in range(N):
        formula = raw_input().rstrip('=')
        up_to_you(formula)

Submission status: Wrong Answer

Solution code:
ol = input()
for oi in xrange(ol):
	s = raw_input()
	s = s[:-1]
	r = eval(s)
	print r

Submission status: Wrong Answer

Solution code:
def seekBackOperatorInLand(op,s):
	depth = 0
	for i in xrange(len(s)-1,-1,-1):
		if s[i]==')': depth+=1
		if s[i]=='(': depth-=1
		if s[i]==op and depth==0: return i
	return None

def calc(s):
	if all(map(lambda t: t in "0123456789", s)):
		return int(s)
	if s[0]=='(' and s[-1]==')' and all(map(lambda t: t!='(' and t!=')', s[1:-1])):
		return calc(s[1:-1])
	
	p = seekBackOperatorInLand('-',s)
	if not p is None: return calc(s[:p])-calc(s[p+1:])
	p = seekBackOperatorInLand('+',s)
	if not p is None: return calc(s[:p])+calc(s[p+1:])
	p = seekBackOperatorInLand('/',s)
	if not p is None: return calc(s[:p])/calc(s[p+1:])
	p = seekBackOperatorInLand('*',s)
	if not p is None: return calc(s[:p])*calc(s[p+1:])

	return calc(s[1:-1])

def main():
	ol=input()
	for oi in xrange(ol):
		print calc(raw_input()[:-1])

main()

Submission status: Wrong Answer

Solution code:
def seekBackOperatorInLand(op,s):
	depth = 0
	for i in xrange(len(s)-1,-1,-1):
		if s[i]==')': depth+=1
		if s[i]=='(': depth-=1
		if s[i]==op and depth==0: return i
	return None

def calc(s):
	if all(map(lambda t: t in "0123456789", s)):
		return int(s)
	if s[0]=='(' and s[-1]==')' and all(map(lambda t: t!='(' and t!=')', s[1:-1])):
		return calc(s[1:-1])
	
	p = seekBackOperatorInLand('-',s)
	if not p is None: return calc(s[:p])-calc(s[p+1:])
	p = seekBackOperatorInLand('+',s)
	if not p is None: return calc(s[:p])+calc(s[p+1:])
	p = seekBackOperatorInLand('/',s)
	if not p is None: return 1.0*calc(s[:p])/calc(s[p+1:])
	p = seekBackOperatorInLand('*',s)
	if not p is None: return calc(s[:p])*calc(s[p+1:])

	return calc(s[1:-1])

def main():
	ol=input()
	for oi in xrange(ol):
		print int(calc(raw_input()[:-1]))

main()

Submission status: Wrong Answer

Solution code:
def seekBackOperatorInLand(op,s):
	depth = 0
	for i in xrange(len(s)-1,-1,-1):
		if s[i]==')': depth+=1
		if s[i]=='(': depth-=1
		if s[i]==op and depth==0: return i
	return None

def calc(s):
	if all(map(lambda t: t in "0123456789", s)):
		return int(s)
	
	p = seekBackOperatorInLand('-',s)
	if not p is None: return calc(s[:p])-calc(s[p+1:])
	p = seekBackOperatorInLand('+',s)
	if not p is None: return calc(s[:p])+calc(s[p+1:])
	p = seekBackOperatorInLand('/',s)
	if not p is None: return calc(s[:p])/calc(s[p+1:])
	p = seekBackOperatorInLand('*',s)
	if not p is None: return calc(s[:p])*calc(s[p+1:])

	return calc(s[1:-1])

def main():
	ol=input()
	for oi in xrange(ol):
		print int(calc(raw_input()[:-1]))

main()

Submission status: Wrong Answer

Solution code:
def seekBackOperatorInLand(op,s):
	depth = 0
	for i in xrange(len(s)-1,-1,-1):
		if s[i]==')': depth+=1
		if s[i]=='(': depth-=1
		if s[i]==op and depth==0: return i
	return None

def calc(s):
	if s=='':
		return 0

	if all(map(lambda t: t in "0123456789", s)):
		return int(s)
	
	p = seekBackOperatorInLand('+',s)
	if not p is None: return calc(s[:p])+calc(s[p+1:])
	p = seekBackOperatorInLand('-',s)
	if not p is None: return calc(s[:p])-calc(s[p+1:])
	p = seekBackOperatorInLand('*',s)
	if not p is None: return calc(s[:p])*calc(s[p+1:])
	p = seekBackOperatorInLand('/',s)
	if not p is None: return calc(s[:p])/calc(s[p+1:])
	
	return calc(s[1:-1])

def main():
	ol=input()
	for oi in xrange(ol):
		print calc(raw_input()[:-1])

main()

Submission status: Wrong Answer

Solution code:
def seekBackOperatorInLand(op,s):
	depth = 0
	for i in xrange(len(s)-1,-1,-1):
		if s[i]==')': depth+=1
		if s[i]=='(': depth-=1
		if s[i]==op and depth==0: return i
	return None

def calc(s):
	if s=='':
		return 0

	if all(map(lambda t: t in "0123456789", s)):
		return int(s)
	
	p = seekBackOperatorInLand('+',s)
	if not p is None: return calc(s[:p])+calc(s[p+1:])
	p = seekBackOperatorInLand('-',s)
	if not p is None: return calc(s[:p])-calc(s[p+1:])
	p = seekBackOperatorInLand('*',s)
	if not p is None: return calc(s[:p])*calc(s[p+1:])
	p = seekBackOperatorInLand('/',s)
	if not p is None: return calc(s[:p])/calc(s[p+1:])
	
	return calc(s[1:-1])

def main():
	ol=input()
	for oi in xrange(ol):
		s=raw_input()[:-1]
		print calc(s) #, eval(s)

main()

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
for i in range(n):
  print eval(raw_input()[:-1])

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
for i in range(n):
    print eval(raw_input()[:-1])

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
for i in range(n):
  print int(eval(raw_input()[:-1]))

Submission status: Wrong Answer

Solution code:
n = input()
for i in range(int(n)):
    command = input()
    answer = eval(command[0:-1])
    print(answer)

Submission status: Wrong Answer

Solution code:
n=int(input())

for t in range(n):
    s=input()
    s=s[:-1]
    print(eval(s))

Submission status: Wrong Answer

Solution code:
n=int(input())

for t in range(n):
    print(eval(input()[:-1].replace("/","//")))

Submission status: Wrong Answer

Solution code:
n=int(input())

for t in range(n):
    s=input()
    s=s[:-1]
    s=s.replace("/","//")
    print(eval(s))

Submission status: Wrong Answer

Solution code:
n = int(input())
[print(eval(input()[:-1])) for i in range(n)]

Submission status: Wrong Answer

Solution code:
n = input()
for i in range(n):
    s = raw_input()[:-1]
    print eval(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
for T in range(n):
    s=input()[0:-1]
    s=s.replace('/','//')
    print(eval(s))

Submission status: Wrong Answer

Solution code:
import sys

input()
for i in sys.stdin.readlines():
        print(eval(i[:-2]))

Submission status: Wrong Answer

Solution code:
import sys

input()
for i in sys.stdin.readlines():
        print(eval(i[:-2].replace('/', '//')))

Submission status: Wrong Answer

Solution code:
import sys

input()
for i in sys.stdin.readlines():
        print(int(eval(i[:-2].replace('/', '//'))))

Submission status: Wrong Answer

Solution code:
import sys

input()
for i in sys.stdin.readlines():
        print(int(eval(i[:-2])))

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
	a=input()
	print(eval(a[:len(a)-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
	a=input()
	print(int(eval(a[:len(a)-1])))

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
	a=input()
	b=""
	for i in a:
		b+=i
		if i=='/':b+='/'
	print(int(eval(a[:len(a)-1])))

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
	a=input()
	b=""
	for i in a:
		b+=i
		if i=='/':b+='/'
	print(int(eval(b[:len(b)-1])))

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
	a=input()
	b=""
	for i in a:
		b+=i
		if i=='/':b+='/'
	print(eval(b[:len(b)-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):print(eval(input()[:-1].replace('/','//')))

Submission status: Wrong Answer

Solution code:

n = int(input())
for i in range(n):
    s = input()
    print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    s = raw_input().split('=')
    print(eval(s[0]))

Submission status: Wrong Answer

Solution code:

import re
n = int(input())
for i in range(n):
    s = raw_input().split('=')
    print(s)
    print(eval(s[0]))

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
for i in range(n):
    s = raw_input().split('=')
    print(eval(s[0]))

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
for _ in range(n):
    expr = input()[0:-1]
    print(eval(expr))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

if __name__ == '__main__':
	num = int(raw_input())
	for i in range(num):
		input_line = raw_input()
		eval_line = input_line[0:-1]
		result = eval(eval_line)
		print result

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

num = int(raw_input())
for i in range(num):
	input_line = raw_input()
	eval_line = input_line[0:-1]
	result = eval(eval_line)
	print result

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    s = input()
    print(eval(s[:-1:]))

Submission status: Wrong Answer

Solution code:
def calc(eqt):
  l = eqt.split("+",maxsplit=1)
  if len(l) == 2:
    return (calc(l[0])+calc(l[1]))
  l = eqt.split("-",maxsplit=1)
  if len(l) == 2:
    return (calc(l[0])-calc(l[1]))
  l = eqt.split("*",maxsplit=1)
  if len(l) == 2:
    return (calc(l[0])*calc(l[1]))
  l = eqt.split("/",maxsplit=1)
  if len(l) == 2:
    return (calc(l[0])//calc(l[1]))
  return (int(eqt))

def unfold_brackets(eqt):
  l = eqt.split(')',maxsplit=1)
  if len(l) == 1:
    return calc(eqt)
  else:
    ll = l[0].rsplit('(',maxsplit=1)
    ll.append(l[1])
    ll[1] = str(calc(ll[1]))
    l="".join(ll)
    return unfold_brackets(l)

print(unfold_brackets("(((3+2)*(5+4))+2)"))

Submission status: Wrong Answer

Solution code:
while True:
  try:
    n=int(input())
    datasets=[input() for i in range(0,n)]
    for line in datasets:
      l = line.split("=",maxsplit=1)[0]
      print(int(eval(l)))
  except EOFError:
    break

Submission status: Wrong Answer

Solution code:
import re
class c(int):
    def __add__(self,n):
        return c(int(self)+int(n))
    def __sub__(self,n):
        return c(int(self)-int(n))
    def __mul__(self,n):
        return c(int(self)*int(n))
    def __floordiv__(self,n):
        return c(int(self)//int(n))

for _ in range(int(input())):
    f = input().replace('/','//')[:-1]
    f = eval(re.sub(r'(\d+)',r'c(\1)',f))
    print(f)

Submission status: Wrong Answer

Solution code:
import re
class c(int):
    def __add__(self,n):
        return c(int(self)+int(n))
    def __sub__(self,n):
        return c(int(self)-int(n))
    def __mul__(self,n):
        return c(int(self)*int(n))
    def __truediv__(self,n):
        return c(int(self)//int(n))
 
for _ in range(int(input())):
    print(eval(re.sub(r'(\d+)',r'c(\1)',input()[:-1])))

Submission status: Wrong Answer

Solution code:
import re
class c:
    def __str__(self):
        return str(self.x)
    def __init__(self,n):
        self.x=n
    def __add__(self,n):
        return c(self.x+n.x)
    def __sub__(self,n):
        return c(self.x-n.x)
    def __mul__(self,n):
        return c(self.x*n.x)
    def __truediv__(self,n):
        return c(self.x//n.x)
  
for _ in range(int(input())):
    print(eval(re.sub(r'(\d+)',r'c(\1)',input()[:-1])))

Submission status: Wrong Answer

Solution code:
n = int(input())
for _ in range(n):
    print(eval(input()[:-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
for _ in range(n):
    print(int(eval(input()[:-1])))

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):
    print(eval(input().replace('/', '//')[:-1]))

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):
    ans = eval(input().replace('/', '//')[:-1])
    print(str(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

n = int(input())

for i in range(n):
    command = input().strip()
    command = command.replace('=', '')
    print(eval(command))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

n = int(input())

for i in range(n):
    command = input().strip()
    command = command.replace('=', '')
    command = command.replace('/', '//')
    print(eval(command))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

n = int(input())

for i in range(n):
    command = input().strip()
    command = command.replace('=', '')
    command = command.replace('/', '//')
    print(command)
    print(int(eval(command)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

n = int(input())

for i in range(n):
    command = input().strip()
    command = command.replace('=', '')
    command = command.replace('/', '//')
    #print(command)
    print(int(eval(command)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import re

class Num:
    def __str__(self):
        return str(self.x)

    def __init__(self, value):
        self.x = value

    def __add__(self,value):
        return Num(self.x + value.x)

    def __sub__(self, value):
        return Num(self.x - value.x)

    def __mul__(self, value):
        return Num(self.x * value.x)

    def __truediv__(self,value):
        return Num(math.ceil(self.x / value.x))

n = int(input())

for i in range(n):
    command = input().strip()
    command = command.replace('=', '')
    command = re.sub(r'(\d+)', r'Num(\1)', command)
    print(eval(command))

# Supplement
# -1 // 2 => -1

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):
    e = input()[:-1].replace("/", "//")
    print(eval(e))

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):
    print(eval(input()[:-1].replace('/', '//')))

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):
    print(int(eval(input()[:-1].replace('/', '//'))))

Submission status: Wrong Answer

Solution code:
num = int(raw_input())
for i in range(num):
	input_line = raw_input()
	eval_line = input_line[0:-1]
	result = eval(eval_line)
	print result

Submission status: Wrong Answer

Solution code:
#n=int(input())

def lastfind(s,x):
    n=len(s)
    s_rev=s[::-1]
    t=s_rev.find(x)
    return n-t-1
def doublefind(s,x,y):
    if x in s:
        p=s.find(x)
    else:
        p=len(s)+10
    if y in s:
        q=s.find(y)
    else:
        q=len(s)+10
    
    if p<=q and p<len(s)+5:
        return [p,x]
    elif q<len(s)+5:
        return [q,y]
    else:
        return 0

def calculator(s):
    if s=="":
        return 0
    
    try:
        return int(s)
    except:
        try:
            x=doublefind(s,"+","-")
            if x[1]=="+":
                return calculator(s[:x[0]:])+calculator(s[x[0]+1::])
            else:
                return calculator(s[:x[0]:])-calculator(s[x[0]+1::])
        except:
            x=doublefind(s,"*","/")
            if x[1]=="*":
                return calculator(s[:x[0]:])*calculator(s[x[0]+1::])
            else:
                return int(calculator(s[:x[0]:])/calculator(s[x[0]+1::]))
def remove_brackets(s):
    if s[0]=="(" and s[-1]==")":
        return s[1:-1:]
    else:
        return s
def calc(s):
    while "(" in s:
        closec=s.find(")")
        openc=lastfind(s[:closec:],"(")
        s=s[:openc:]+str(calculator(s[openc+1:closec:]))+s[closec+1::]
    return calculator(s)
        
n=int(input())
for count in range(n):
    s=input()
    print(calc(s[:-1:]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0109&lang=jp
"""
import sys



def solve(exp):
    exp = exp.replace('=', '')
    exp = exp.replace('/', '//')
    return eval(exp)


def main(args):
    n = int(input())
    for _ in range(n):
        expression = input()
        result = solve(expression)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0109&lang=jp
"""
import sys


def solve(exp):
    exp = exp.replace('=', '')
    exp = exp.replace('/', '//')
    return eval(exp)


def main(args):
    n = int(input())
    for _ in range(n):
        expression = input().strip()
        result = solve(expression)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0109&lang=jp
"""
import sys


def solve(exp):
    exp = exp.replace('=', '')
    #exp = exp.replace('/', '//')
    return int(eval(exp))


def main(args):
    n = int(input())
    for _ in range(n):
        expression = input().strip()
        result = solve(expression)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# ???????????????????¨?????????°???????????????????????????????????????????????????
def RPN_cul(L):
    St = []

    for i in L:
        if i == '+':
            St.append(int(St.pop()) + int(St.pop()))
        elif i == '-':
            St.append(-int(St.pop()) + int(St.pop()))
        elif i == '*':
            St.append(int(St.pop()) * int(St.pop()))
        elif i == '/':
            a = int(St.pop())
            b = int(St.pop())
            St.append(b/a)
        else:
            St.append(i)
    
    return St[0]


# ??????????????????????????????????????¬??§?????°???????????????????????????????????????
def String2List(s):
    L = []
    flag = True
    l = len(s)
    for i in range(l):
        if s[i].isdigit() and flag:
            t = ""
            j = 0
            while s[i+j].isdigit():
                t += s[i+j]
                if i+j == l-1:
                    break
                j += 1
            L.append(t)
            flag = False

        elif not s[i].isdigit():
            L.append(s[i])
            flag = True

    return L

# ???????¨?????????°????????????????????????????????????????¨?????????°????????????????????????
def RPN_list(L):
    S, L2 = [], []
    table = {"*": 1, "/": 1, "+": 0, "-": 0, "(": -1, ")": -1}
    rpn = ""
    for i in L:
        if i.isdigit():
            L2.append(i)
        elif i == "(":
            S.append(i)
        elif i == ")":
            while S[-1] != "(":
                L2.append(S.pop())
            S.pop()
        else:
            if len(S) != 0 and table[S[-1]] > table[i]:
                L2.append(S.pop())            
            S.append(i)

    while len(S) != 0:
        L2.append(S.pop())

    return L2

def main():
    N = int(raw_input())

    for i in range(N):
        s = raw_input()
        L = String2List(s[:-1])
        L = RPN_list(L)
        print RPN_cul(L)

main()

Submission status: Wrong Answer

Solution code:
def RPN_cul(L):
    St = []

    for i in L:
        if i == '+':
            St.append(int(St.pop()) + int(St.pop()))
        elif i == '-':
            St.append(-int(St.pop()) + int(St.pop()))
        elif i == '*':
            St.append(int(St.pop()) * int(St.pop()))
        elif i == '/':
            a = int(St.pop())
            b = int(St.pop())
            St.append(b/a)
        else:
            St.append(i)
    
    return St[0]


def String2List(s):
    L = []
    flag = True
    l = len(s)
    for i in range(l):
        if s[i].isdigit() and flag:
            t = ""
            j = 0
            while s[i+j].isdigit():
                t += s[i+j]
                if i+j == l-1:
                    break
                j += 1
            L.append(t)
            flag = False

        elif not s[i].isdigit():
            L.append(s[i])
            flag = True

    return L


def RPN_list(L):
    S, L2 = [], []
    table = {"*": 1, "/": 1, "+": 0, "-": 0, "(": -1, ")": -1}
    rpn = ""
    for i in L:
        if i.isdigit():
            L2.append(i)
        elif i == "(":
            S.append(i)
        elif i == ")":
            while S[-1] != "(":
                L2.append(S.pop())
            S.pop()
        else:
            if len(S) != 0 and table[S[-1]] >= table[i]:
                L2.append(S.pop())            
            S.append(i)

    while len(S) != 0:
        L2.append(S.pop())

    return L2

def main():
    N = int(raw_input())

    for i in range(N):
        s = raw_input()
        L = String2List(s[:-1])
        L = RPN_list(L)
        print RPN_cul(L)

main()

Submission status: Wrong Answer

Solution code:
def RPN_cul(L):
    St = []

    for i in L:
        if i == '+':
            St.append(int(St.pop()) + float(St.pop()))
        elif i == '-':
            St.append(-int(St.pop()) + float(St.pop()))
        elif i == '*':
            St.append(int(St.pop()) * float(St.pop()))
        elif i == '/':
            a = int(St.pop())
            b = float(St.pop())
            St.append(b/a)
        else:
            St.append(i)
    
    return St[0]


def String2List(s):
    L = []
    flag = True
    l = len(s)
    for i in range(l):
        if s[i].isdigit() and flag:
            t = ""
            j = 0
            while s[i+j].isdigit():
                t += s[i+j]
                if i+j == l-1:
                    break
                j += 1
            L.append(t)
            flag = False

        elif not s[i].isdigit():
            L.append(s[i])
            flag = True

    return L


def RPN_list(L):
    S, L2 = [], []
    table = {"*": 1, "/": 1, "+": 0, "-": 0, "(": -1, ")": -1}
    rpn = ""
    for i in L:
        if i.isdigit():
            L2.append(i)
        elif i == "(":
            S.append(i)
        elif i == ")":
            while S[-1] != "(":
                L2.append(S.pop())
            S.pop()
        else:
            if len(S) != 0 and table[S[-1]] >= table[i]:
                L2.append(S.pop())            
            S.append(i)

    while len(S) != 0:
        L2.append(S.pop())

    return L2


def main():
    N = int(raw_input())

    for i in range(N):
        s = raw_input()
        L = String2List(s[:-1])
        L = RPN_list(L)
        print int(RPN_cul(L))

main()