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:
R={"*":2,"/":2,"+":1,"-":1,"(":0,")":0}
for _ in[0]*int(input()):
 L=[];t=''
 for e in input()[:-1]:
  if e.isdigit():t+=e
  else:
   if t:L+=[t];t=''
   L+=e
 if t:L+=[t]
 P,S=[],[]
 for i in L:
  if"("==i:S+=i
  elif")"==i:
   while"("!=S[-1]:P+=S.pop()
   S.pop()
  elif i in R:
   while S and R[S[-1]]>=R[i]:P+=S.pop()
   S+=i
  else:P+=[i]
 while S:P+=S.pop()
 for x in P:
  S+=[str(eval(S.pop(-2)+x+S.pop()))if x in"+-*/"else x]
 print(*S)

Submission status: Wrong Answer

Solution code:
# In the name of Allah
for i in range(input()):
    x=raw_input()[:-1]
    print eval(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = int(input())
for l in range(N):
    S = input()
    if S == "exit":
        break
    S = S[0:len(S)-1]
    print(eval(S))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# AOJ 0109 Smart Calculator
# Python3 2018.6.18 bal4u

INF = 1000000010
LEFT  = INF+1
RIGHT = INF+2
PLUS  = INF+3
MINUS = INF+4
MUL   = INF+5
DIV   = INF+6
token = { '+':PLUS, '-':MINUS, '*':MUL, '/':DIV }
rank = { PLUS:2, MINUS:2, MUL:3, DIV:3, LEFT:1, RIGHT:1 }

S, top = [0]*200, 0
Q, end = [0]*200, 0

def getInt():
	global id
	k = ''
	while buf[id] >= '0' and buf[id] <= '9':
		k += buf[id]
		id += 1
	return int(k)

n = int(input())
for i in range(n):
	buf = list(input())
	id, f, top, end = 0, True, 0, 0
	while True:
		if buf[id] == '=':
			while top > 0:
				top -= 1
				Q[end] = S[top]
				end += 1
			break;
		if buf[id] == '-' and f and buf[id+1] >= '0' and buf[id+1] <= '9':
			id += 1
			Q[end] = -getInt()
			end += 1
			f = False
			continue
		
		f = False
		if buf[id] >= '0' and buf[id] <= '9':
			Q[end] = getInt()
			end += 1
		elif buf[id] == ')':
			while S[top - 1] != LEFT:
				top -= 1
				Q[end] = S[top]
				end += 1
			top -= 1
			id += 1
		elif buf[id] == '(':
			S[top] = LEFT
			top += 1
			id += 1
			f = True
		else:
			k = token[buf[id]]
			id += 1
			while top > 0:
				if rank[k] <= rank[S[top-1]]:
					top -= 1
					Q[end] = S[top];
					end += 1
				else: break
			S[top] = k;
			top += 1
	top = 0
	for i in range(end):
		k = Q[i]
		if k > INF:
			d1, d2 = S[top-1], S[top-2]
			top -= 2
			if k == PLUS: d2 += d1
			elif k == MINUS: d2 -= d1
			elif k == MUL: d2 *= d1
			else: d2 //= d1
			S[top] = d2
		else: S[top] = k
		top += 1
	print(S[top-1])

Submission status: Wrong Answer

Solution code:
# AOJ 0109 Smart Calculator
# Python3 2018.6.18 bal4u

INF = 1000000010
LEFT  = INF+1
RIGHT = INF+2
PLUS  = INF+3
MINUS = INF+4
MUL   = INF+5
DIV   = INF+6
token = { '+':PLUS, '-':MINUS, '*':MUL, '/':DIV }
rank = { PLUS:2, MINUS:2, MUL:3, DIV:3, LEFT:1, RIGHT:1 }

S, top = [0]*200, 0
Q, end = [0]*200, 0

def getInt():
	global id
	global buf
	k = ''
	while buf[id] >= '0' and buf[id] <= '9':
		k += buf[id]
		id += 1
	return int(k)

n = int(input())
for i in range(n):
	buf = list(input())
	id, f, top, end = 0, True, 0, 0
	while True:
		if buf[id] == '=':
			while top > 0:
				top -= 1
				Q[end] = S[top]
				end += 1
			break;
		if buf[id] == '-' and f and buf[id+1] >= '0' and buf[id+1] <= '9':
			id += 1
			Q[end] = -getInt()
			end += 1
			f = False
			continue
		
		f = False
		if buf[id] >= '0' and buf[id] <= '9':
			Q[end] = getInt()
			end += 1
		elif buf[id] == ')':
			while S[top - 1] != LEFT:
				top -= 1
				Q[end] = S[top]
				end += 1
			top -= 1
			id += 1
		elif buf[id] == '(':
			S[top] = LEFT
			top += 1
			id += 1
			f = True
		else:
			k = token[buf[id]]
			id += 1
			while top > 0:
				if rank[k] <= rank[S[top-1]]:
					top -= 1
					Q[end] = S[top];
					end += 1
				else: break
			S[top] = k;
			top += 1
	top = 0
	for i in range(end):
		k = Q[i]
		if k > INF:
			d1, d2 = S[top-1], S[top-2]
			top -= 2
			if k == PLUS: d2 += d1
			elif k == MINUS: d2 -= d1
			elif k == MUL: d2 *= d1
			else:
				d2 //= d1
				if d2 < 0: d2 += 1	## -5 // 2 = -3 (Pythonでは)
			S[top] = d2
		else: S[top] = k
		top += 1
	print(S[top-1])

Submission status: Wrong Answer

Solution code:
print(*[eval(input()[:-1]) for _ in range(int(input()))], sep="\n")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
print(*[eval(input()[:-1].replace("/", "//")) for _ in range(int(input()))], sep="\n")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 写経した
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(self.x // value.x)
      
N = int(input())
for i in range(N):
    s = input()[:-1]
    s = re.sub(r'(\d+)',r'Num(\1)',s)
    print(eval(s))

Submission status: Wrong Answer

Solution code:
N = int(input())
for i in range(N):
    print(int(eval(input().replace("/","//").strip("="))))

Submission status: Wrong Answer

Solution code:
from collections import deque

def eva(l, r, op):
    if op == "+":
        return l + r
    elif op == "-":
        return l - r
    elif op == "*":
        return l * r
    elif op == "/":
        return l // r


def calc(exp):
    i = 0
    num = deque()
    ops = deque()
    ope = ""
    while i < len(exp):
        if exp[i] == '(':
            end = 1
            s = 1
            while True:
                if exp[i+end] == "(":
                    s += 1
                elif exp[i+end] == ")":
                    s -= 1
                if s == 0:
                    break
                end += 1
            num.append(calc(exp[i+1:i+end]))
            i += end
            if ope:
                l = num.pop()
                r = num.pop()
                num.append(eva(l, r, ope))
                ope = ""
        elif exp[i] in ["*", "/"]:
            ope = exp[i]
        elif exp[i] in ["+", "-"]:
            ops.append(exp[i])
        elif exp[i] == "=":
            pass
        else:
            temp = ""
            j = 0
            while i + j < len(exp) and exp[i+j].isnumeric():
                temp += exp[i+j]
                j += 1
            num.append(int(temp))
            i += j - 1
            if ope:
                num.append(eva(num.pop(), num.pop(), ope))
                ope = ""
        i += 1
    while len(ops) != 0:
        l = num.popleft()
        r = num.popleft()
        num.appendleft(eva(l,r,ops.popleft()))
    
    return num[0]


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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys

def main():
	n = input()
	for i in xrange(n):
		line = raw_input()
		exec("print %s" % line[:-1])
	return 0

if __name__ == '__main__':
	sys.exit(main())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
n = input()
for i in xrange(n):
	line = raw_input()
	exec("x = %s" % line[:-1])
	print x

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import re
n = input()
for i in xrange(n):
	line = raw_input()
	re.sub("\.\d*", "", line)
	exec("x = %s" % line[:-1])
	print x

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
pos = 0
def number(s):
	global pos
	result = 0
	while s[pos].isdigit():
		result *= 10
		result += int(s[pos])
		pos += 1
	return result;
expression = None
def factor(s):
	global pos
	if s[pos] == '(':
		pos += 1
		result = expression(s)
		pos += 1
		return result
	else:
		return number(s)
def term(s):
	global pos
	result = factor(s)
	while True:
		if s[pos] == '*':
			pos += 1
			result *= factor(s)
		elif s[pos] == '/':
			pos += 1
			result /= factor(s)
		else:
			break
	return result
def _expression(s):
	global pos
	result = term(s)
	while True:
		if s[pos] == '+':
			pos += 1
			result += term(s)
		elif s[pos] == '-':
			pos += 1
			result -= term(s)
		else:
			break
	return result
expression = _expression

n = input()
for i in xrange(n):
	pos = 0
	print expression(raw_input())

Submission status: Wrong Answer

Solution code:
pos = 0
def number(s):
	global pos
	x = pos
	while s[pos].isdigit():
		pos += 1
	return int(s[x:pos])
expression = None
def factor(s):
	global pos
	if s[pos] == '(':
		pos += 1
		result = expression(s)
		pos += 1
		return result
	else:
		return number(s)
def term(s):
	global pos
	result = factor(s)
	while True:
		if s[pos] == '*':
			pos += 1
			result *= factor(s)
		elif s[pos] == '/':
			pos += 1
			result = int(result / factor(s))
		else:
			break
	return result
def _expression(s):
	global pos
	result = term(s)
	while True:
		if s[pos] == '+':
			pos += 1
			result += term(s)
		elif s[pos] == '-':
			pos += 1
			result -= term(s)
		else:
			break
	return result
expression = _expression

n = input()
for i in xrange(n):
	pos = 0
	print expression(raw_input())

Submission status: Wrong Answer

Solution code:
pos = 0
def number(s):
	global pos
	x = pos
	if s[pos] == '-' or s[pos] == '+':
		pos += 1
	while s[pos].isdigit():
		pos += 1
	return int(s[x:pos])
expression = None
def factor(s):
	global pos
	if s[pos] == '(':
		pos += 1
		result = expression(s)
		pos += 1
		return result
	else:
		return number(s)
def term(s):
	global pos
	result = factor(s)
	while True:
		if s[pos] == '*':
			pos += 1
			result *= factor(s)
		elif s[pos] == '/':
			pos += 1
			result = int(result / factor(s))
		else:
			break
	return result
def _expression(s):
	global pos
	result = term(s)
	while True:
		if s[pos] == '+':
			pos += 1
			result += term(s)
		elif s[pos] == '-':
			pos += 1
			result -= term(s)
		else:
			break
	return result
expression = _expression

for i in xrange(input()):
	pos = 0
	print expression(raw_input())

Submission status: Wrong Answer

Solution code:
pos = 0
def number(s):
	global pos
	x = pos
	if s[pos] == '-' or s[pos] == '+':
		pos += 1
	while s[pos].isdigit():
		pos += 1
	return int(s[x:pos])
expression = None
def factor(s):
	global pos
	if s[pos] == '(':
		pos += 1
		result = expression(s)
		pos += 1
		return result
	else:
		return number(s)
def term(s):
	global pos
	result = factor(s)
	while True:
		if s[pos] == '*':
			pos += 1
			result *= factor(s)
		elif s[pos] == '/':
			pos += 1
			x = factor(s)
			result = int(result / abs(x)) * cmp(x, 0)
		else:
			break
	return result
def _expression(s):
	global pos
	result = term(s)
	while True:
		if s[pos] == '+':
			pos += 1
			result += term(s)
		elif s[pos] == '-':
			pos += 1
			result -= term(s)
		else:
			break
	return result
expression = _expression

for i in xrange(input()):
	pos = 0
	print expression(raw_input())

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 unused in xrange(input()):print eval(raw_input().strip("="))

Submission status: Wrong Answer

Solution code:
for unused in xrange(input()):print eval(raw_input().strip("="))+0

Submission status: Wrong Answer

Solution code:
for u in xrange(input()):print eval(raw_input().strip("="))

Submission status: Wrong Answer

Solution code:
for u in xrange(input()):print int(eval(raw_input().strip("=")))

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 i in range(int(raw_input())):
    print eval(raw_input().rstrip(' \t\r\n='))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math;
for i in range(int(raw_input())):
	print int(math.floor(eval(raw_input()[:-1])));

Submission status: Wrong Answer

Solution code:
def calc(a,b,op):
    if op == "+":
        return b+a
    if op == "-":
        return b-a
    if op == "*":
        return b*a
    if op == "/":
        return b/a
def RPN(reg):
    OP = ["+","-","*","/"]
    stack = []
    for r in reg:
        if r in OP:
            stack.append(calc(stack.pop(),stack.pop(),r))
        else:
            r = int(r)
            stack.append(r)
    return stack[0]
def toRPN(exp):
    OP = ["+","-","*","/","(",")"]
    PR = {"+":1,"-":1,"*":2,"/":2,"(":0,")":0}
    rpn = []
    stack = []
    for e in exp:
        if e in OP:
            if e == "(":
                stack.append(e)
            elif e == ")":
                while True:
                    s = stack.pop()
                    if s == "(":
                        break
                    rpn.append(s)
            else:
                stack.append(e)
                while True:
                    s = stack.pop()
                    if (not stack) or s in ["(",")"] or (PR[stack[-1]] <= PR[s]):
                        stack.append(s)
                        break
                    rpn.append(stack.pop())
                    stack.append(s)
        else:
            rpn.append(e)
    for s in stack[::-1]:
        rpn.append(s)
    return rpn
def splitEXP(st):
    OP = ["+","-","*","/","(",")"]
    temp = ""
    exp = []
    for s in st:
        if s in OP:
            if not temp == "":
                exp.append(temp)
                temp = ""
            exp.append(s)
        else:
            temp += s
    if not temp == "":
        exp.append(temp)
    return exp
    
if __name__ == "__main__":
    """
    print toRPN(["3","+","2","/","2"])
    print toRPN(["(","2","+","2",")","/","(","2","+","2",")"])
    print toRPN(["2","/","2","+","2","/","2","+","2","/","2"])
    """
    for u in xrange(input()):
        exp = splitEXP(raw_input().strip("="))
        print RPN(toRPN(exp))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = input()
for _t in range(n):
    print int(eval("float("+raw_input().rstrip("=")+")") + 1e-16)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    exec "c="+raw_input()[:-1]
    print c

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    print eval("".join([i for i in raw_input() if i!="="]))

Submission status: Wrong Answer

Solution code:
from __future__ import division
for i in range(input()):
    print int(eval(raw_input()[:-1]))

Submission status: Wrong Answer

Solution code:

import sys


def solv(expr):
    expr = expr.rstrip('=')
    return eval(expr)



while True:
    try:
        n = int(sys.stdin.readline())
        for i in range(n):
            expr = sys.stdin.readline().rstrip('\n')
            print solv(expr)
    except:
        exit()

Submission status: Wrong Answer

Solution code:

import sys


class Scanner:
    def __init__(self, str):
        str = str.rstrip('=')
        str = '(' + str + ')'
        self.tokens = self.tokenize(str)

    def tokenize(self, str):
        x = list(str)
        t = []
        while True:
            if not x:
                break
            c = x.pop(0)
            if c == '(':
                t.append(c)
            elif c == ')':
                t.append(c)
            elif c == '+':
                t.append(c)
            elif c == '-':
                t.append(c)
            elif c == '*':
                t.append(c)
            elif c == '/':
                t.append(c)
            else:
                while True:
                    if len(x) > 0 and x[0].isdigit():
                        c = c + x.pop(0)
                    else:
                        break
                t.append(c)
        return t

    def next(self):
        if self.tokens:
            return self.tokens.pop(0)
        else:
            return None



class Calculator:
    def __init__(self, scanner):
        self.scanner = scanner
        self.stack = []

    def calc(self):
        while True:
            t = self.scanner.next()
            if t:
                if t == ')':
                    e = t
                    while True:
                        t2 = self.stack.pop()
                        if not t2 == '(':
                            e = t2 + e
                        else:
                            e = t2 + e
                            e = ''.join(e)
                            r = eval(e)
                            self.stack.append(str(r))
                            break
                else:
                    self.stack.append(t)
            else:
                return self.stack.pop()



def solv(expr):
    scanner = Scanner(expr)
    calculator = Calculator(scanner)
    return calculator.calc()


while True:
    try:
        n = int(sys.stdin.readline())
        for i in range(n):
            expr = sys.stdin.readline().rstrip('\n')
            print solv(expr)
    except:
        exit()

Submission status: Wrong Answer

Solution code:

import sys
import math


class Scanner:
    def __init__(self, str):
        str = str.rstrip('=')
        str = '(' + str + ')'
        self.tokens = self.tokenize(str)

    def tokenize(self, str):
        x = list(str)
        t = []
        while True:
            if not x:
                break
            c = x.pop(0)
            if c == '(':
                t.append(c)
            elif c == ')':
                t.append(c)
            elif c == '+':
                t.append(c)
            elif c == '-':
                t.append(c)
            elif c == '*':
                t.append(c)
            elif c == '/':
                t.append(c)
            else:
                while True:
                    if len(x) > 0 and x[0].isdigit():
                        c = c + x.pop(0)
                    else:
                        break
                t.append(c)
        return t

    def next(self):
        if self.tokens:
            return self.tokens.pop(0)
        else:
            return None



class Calculator:
    def __init__(self, scanner):
        self.scanner = scanner
        self.stack = []

    def calc(self):
        while True:
            t = self.scanner.next()
            if t:
                if t == ')':
                    e = [t]
                    while True:
                        t2 = self.stack.pop()
                        if t2 == '(':
                            e.insert(0, t2)
                            e = ''.join(e)
                            r = eval(e)
                            self.stack.append(str(r))
                            break
                        elif t2 == '/':
                            t3 = e.pop(0)
                            t4 = self.stack.pop()
                            e = ['div(', t4, ',', t3, ')'] + e
                        else:
                            e.insert(0, t2)
                else:
                    self.stack.append(t)
            else:
                return self.stack.pop()



def div(a, b):
    a = float(a)
    b = float(b)
    c = a / b
    if c < 0.0:
        return int(math.ceil(c))
    else:
        return int(math.floor(c))


def solv(expr):
    scanner = Scanner(expr)
    calculator = Calculator(scanner)
    return calculator.calc()


while True:
    try:
        n = int(sys.stdin.readline())
        for i in range(n):
            expr = sys.stdin.readline().rstrip('\n')
            print solv(expr)
    except:
        exit()

Submission status: Wrong Answer

Solution code:
while True:
    line = raw_input()
    if line == '':
        break

    n = int(line)
    for i in range(n):
        print eval(raw_input().strip()[:-1])

Submission status: Wrong Answer

Solution code:
while True:
    line = raw_input()
    if line == '':
        break

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

Submission status: Wrong Answer

Solution code:
while True:
    line = raw_input()
    if line == '':
        break

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

Submission status: Wrong Answer

Solution code:
while True:
    line = raw_input()
    if line == '':
        break

    for i in range(int(line)):
        a = eval(raw_input().replace('/', '//')[:-1])
        print int(a)

Submission status: Wrong Answer

Solution code:
import sys

while True:
    line = raw_input()
    if line == '':
        break

    for i in range(int(line)):
        a = eval(raw_input().replace('/', '//')[:-1])
        print(str(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re

def expression():
    global pos
    ret=term()
    while True:
        if L[pos]=="+":
            pos+=1
            ret+=term()
        elif L[pos]=="-":
            pos+=1
            ret-=term()
        else:
            break
    return ret

def term():
    global pos
    ret=factor()
    while True:
        if L[pos]=="*":
            pos+=1
            ret*=factor()
        elif L[pos]=="/":
            pos+=1
            ret/=factor()
        else:
            break
    return ret

def factor():
    global pos
    if L[pos]=="(":
        pos+=1
        ret=expression()
        pos+=1
    else:
        return number()
    return ret

def number():
    global pos
    ret=0
    if L[pos].isdigit():
        ret=int(L[pos])
        pos+=1
    return ret

for i in range(input()):
    s=raw_input()
    L=re.findall(r"\d+|[/+*-]|[\(\)=]",s)
    pos=0
    print expression()

Submission status: Wrong Answer

Solution code:
import re

def expression():
    global pos
    ret=term()
    while True:
        if L[pos]=="+":
            pos+=1
            ret+=term()
        elif L[pos]=="-":
            pos+=1
            ret-=term()
        else:
            break
    return ret

def term():
    global pos
    ret=factor()
    while True:
        if L[pos]=="(":
            ret+=factor()
        elif L[pos]=="*":
            pos+=1
            ret*=factor()
        elif L[pos]=="/":
            pos+=1
            ret/=factor()
        else:
            break
    return ret

def factor():
    global pos
    if L[pos]=="(":
        pos+=1
        ret=expression()
        pos+=1
    else:
        return number()
    return ret

def number():
    global pos
    ret=0
    if L[pos].isdigit():
        ret=int(L[pos])
        pos+=1
    return ret

for i in range(input()):
    s=raw_input()
    L=re.findall(r"\d+|[/+*-]|[\(\)=]",s)
    pos=0
    print expression()

Submission status: Wrong Answer

Solution code:
def expression():
    global pos
    ret=term()
    while True:
        if L[pos]=="+":
            pos+=1
            ret+=term()
        elif L[pos]=="-":
            pos+=1
            ret-=term()
        else:
            break
    return ret

def term():
    global pos
    ret=factor()
    while True:
        if L[pos]=="(":
            ret+=factor()
        elif L[pos]=="*":
            pos+=1
            ret*=factor()
        elif L[pos]=="/":
            pos+=1
            ret/=factor()
        else:
            break
    return ret

def factor():
    global pos
    if L[pos]=="(":
        pos+=1
        ret=expression()
        pos+=1
    else:
        return number()
    return ret

def number():
    global pos
    ret=0
    while L[pos].isdigit():
        ret*=10
        ret+=int(L[pos])
        pos+=1
    return ret

for i in range(input()):
    L=raw_input()
    pos=0
    print expression()

Submission status: Wrong Answer

Solution code:
i = 0

def number(begin):
	global i
	
	if begin[i] == "(":
		i += 1
		res = expression(begin)
		i += 1 
		return res
	
	res = 0
	
	while begin[i].isdigit():
		res *= 10
		res += int(begin[i])
		i+=1
	
	return res
	
def term(begin):# your code goes here

	global i
	res = number(begin)
	
	while True:
		if begin[i] == "*":
			i += 1
			res *= number(begin)
		elif begin[i] == "/":
			i += 1
			res /= number(begin)
		else:
			break
	return res
	
def expression(begin):
	
	global i
	res = term(begin)
	
	while True:
		if begin[i] == "+":
			i += 1
			res += term(begin)
			
		elif begin[i] == "-":
			i += 1
			res -= term(begin)
		else:
			break
	return res
	

def main():
	ex = raw_input() +"="
	ans = expression(ex)
	
	print ans
	print i
	
main()

Submission status: Wrong Answer

Solution code:
i = 0

def number(begin):
	global i
	
	if begin[i] == "(":
		i += 1
		res = expression(begin)
		i += 1 
		return res
	
	res = 0
	
	while begin[i].isdigit():
		res *= 10
		res += int(begin[i])
		i+=1
	
	return res
	
def term(begin):# your code goes here

	global i
	res = number(begin)
	
	while True:
		if begin[i] == "*":
			i += 1
			res *= number(begin)
		elif begin[i] == "/":
			i += 1
			res /= number(begin)
		else:
			break
	return res
	
def expression(begin):
	
	global i
	res = term(begin)
	
	while True:
		if begin[i] == "+":
			i += 1
			res += term(begin)
			
		elif begin[i] == "-":
			i += 1
			res -= term(begin)
		else:
			break
	return res
	

def main():
	ex = raw_input() +"="
	ans = expression(ex)
	
	print ans
	
main()

Submission status: Wrong Answer

Solution code:

def number(begin):
	global i
	
	if begin[i] == "(":
		i += 1
		res = expression(begin)
		i += 1 
		return res
	
	res = 0
	
	while begin[i].isdigit():
		res *= 10
		res += int(begin[i])
		i+=1
	
	return res
	
def term(begin):# your code goes here

	global i
	res = number(begin)
	
	while True:
		if begin[i] == "*":
			i += 1
			res *= number(begin)
		elif begin[i] == "/":
			i += 1
			res /= number(begin)
		else:
			break
	return res
	
def expression(begin):
	
	global i
	res = term(begin)
	
	while True:
		if begin[i] == "+":
			i += 1
			res += term(begin)
			
		elif begin[i] == "-":
			i += 1
			res -= term(begin)
		else:
			break
	return res
	

def main():
	global i
	for j in range(input()):
			i = 0
			ex = raw_input() +"="
			ans = expression(ex)
	
			print ans
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re

def factor(t, i):
    if t[i[0]] == '(':
        i[0] += 1
        return expr(t, i)
    else:
        r = int(t[i[0]])
        i[0] += 1
        return r

def term(t, i):
    r = factor(t, i)
    while True:
        if t[i[0]] == '*':
            i[0] += 1
            r *= factor(t, i)
        elif t[i[0]] == '/':
            i[0] += 1
            r /= factor(t, i)
        else:
            break
    return r

def expr(t, i):
    r = term(t, i)
    while True:
        if t[i[0]] == '+':
            i[0] += 1
            r += term(t, i)
        elif t[i[0]] == '-':
            i[0] += 1
            r -= term(t, i)
        else:
            break
    return r

n = int(raw_input())
for _ in range(n):
    t = re.sub(r'([\+\-\*\/\(\)=])', r' \1 ', raw_input()).split()
    print expr(t, [0])