Problem:


問題 2 

　加減乗除の計算をする電卓プログラムを作りなさい．

　入力データの各行には数と記号 +, -, *, /, = のどれか1つが交互に書いてある．
１行目は数である．
演算 +, -, *, / の優先順位（乗除算 *, / を加減算 +, - よりも先に計算すること）は考えず，入力の順序で計算し，= の行になったら，計算結果を出力する．
入力データの数値は108以下の正の整数とする．
計算中および計算結果は，0または負の数になることもあるが
 -108〜108 の範囲は超えない．
割り算は切り捨てとする．
したがって，100/3*3= は 99 になる．

　出力ファイルにおいては，
出力の最後の行にも改行コードを入れること．

入出力例

入力例１

1
+
1
=

出力例１

2

入力例２

10
-
21
*
5
=

出力例２

-55

入力例３

100
/
3
*
3
=

出力例３

99

問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
1
+
1
=


Sample output:
2

Submission status: Wrong Answer

Solution code:
a = int(input())
while True:
	b = input();
	if b == '=':
		break
	c = int(input())
	if b == '+':
		a += c
	elif b == '-':
		a -= c
	elif b == '*':
		a *= c
	elif b == '/':
		a /= c
	print(a)

Submission status: Wrong Answer

Solution code:
a = int(input())
while True:
	b = input();
	if b == '=':
		break
	c = int(input())
	if b == '+':
		a += c
	elif b == '-':
		a -= c
	elif b == '*':
		a *= c
	elif b == '/':
		a /= c
print(a)

Submission status: Wrong Answer

Solution code:
import sys
def line():return sys.stdin.readline().strip()

e=""
while True:
    try:
        temp = line()
        if temp=="/":
            e+="//"
        elif temp=="=":
            print(eval(e))
            break
        else:
            e+=temp
    except:
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
while True:
    s = input()
    if s == "-":
        n -= int(input())
    elif s == "+":
        n += int(input())
    elif s =="*":
        n *= int(input())
    elif s == "/":
        n /= int(input())
    else:
        print(n)
        break

Submission status: Wrong Answer

Solution code:
record = None
while True:
    x = input()
    if x == "=":
        break

    if x == "+" or x == "-" or x == "*" or x == "/":
        op = x
    elif record == None:
        record = x
    else:
        record = eval(str(record) + op + x)

print(record)

Submission status: Wrong Answer

Solution code:
# AOJ 0588: Simple Calculator
# Python3 2018.6.30 bal4u

a = int(input())
while True:
	op = input().strip()
	print(op)
	if op == '=': break
	b = int(input()) 
	if      op == '+': a += b
	elif s == '-': a -= b
	elif s == '*': a *= b
	else:          a //= b
print(a)

Submission status: Wrong Answer

Solution code:
a = 0
o = ""
while True:
  s = raw_input()
  print s
  if s == "=":
    break
  if s in ["+", "-", "*", "/"]:
    o = s
  else:
    a = eval(str(a) + o + s)
print a

Submission status: Wrong Answer

Solution code:
expr = "";
s = "";
while s != "=":
	s = raw_input();
	expr += s;

print "%d" % eval(expr[:-1])

Submission status: Wrong Answer

Solution code:
e=""
while True:
	e+=raw_input()
	if e[-1]=="=":break
print eval(e[:-1])

Submission status: Wrong Answer

Solution code:
e=""
while 1:
	e+=raw_input()
	if e[-1]=="=":break
print eval(e[:-1])

Submission status: Accepted

Solution code:
tot = int(input())
while(True) :
    c = input()
    
    if c == '+' :
        tot += int(input())
    elif c == '-' :
        tot -= int(input())
    elif c == '*' :
        tot *= int(input())
    elif c == '/' :
        tot //= int(input())
    else :
        print(tot)
        break

Submission status: Accepted

Solution code:
a = int(input())
while True:
    op = input()
    if op == '=': break
    b = int(input())
    if op == '+':
        a += b
    elif op == '-':
        a -= b
    elif op == '*':
        a *= b
    elif op == '/':
        a //= b
print(a)

Submission status: Accepted

Solution code:
i = input()
while 1:
    s = raw_input()
    if s == "=":
        print i
        break
    n = input()
    if s == "+": i += n
    elif s == "-": i -= n
    elif s == "*": i *= n
    elif s == "/": i /= n

Submission status: Accepted

Solution code:
start = input()

while True:
	command = raw_input()
	if command == "=" : break
	n = input()
	
	if command == "+" : start += n
	if command == "-" : start -= n
	if command == "*" : start *= n
	if command == "/" : start /= n
	
print start

Submission status: Accepted

Solution code:
a = int(input())
while True:
	b = input();
	if b == '=':
		break
	c = int(input())
	if b == '+':
		a += c
	elif b == '-':
		a -= c
	elif b == '*':
		a *= c
	elif b == '/':
		a //= c
print(a)

Submission status: Accepted

Solution code:
import sys
def line():return sys.stdin.readline().strip()

e=""
ans=0
while True:
    try:
        temp = line()
        if temp=="/":
            e+="//"
        elif temp=="*":
            e+="*"
        elif temp=="+":
            e+="+"
        elif temp=="-":
            e+="-"
        elif temp=="=":
            print(eval(e))
            break
        else:
            e+=temp
            ans=eval(e)
            e=str(ans)            
    except:
        break

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    opcode = []                 # ?????????????¨???¶??¨
    operand = []                # ?????´????¢??????????????¨???¶??¨

    # ??????????????\???
    while True:
        data = input()
        if data == '=':
            break
        elif data == '+' or data == '-' or data == '*' or data == '/':
            opcode.append(data)
        else:
            if len(operand) == 0:
                operand.append(int(data))
            else:
                op = opcode.pop()
                operand1 = operand.pop()
                operand2 = int(data)
                if op == '+':
                    operand.append(operand1 + operand2)
                elif op == '-':
                    operand.append(operand1 - operand2)
                elif op == '*':
                    operand.append(operand1 * operand2)
                elif op == '/':
                    operand.append(operand1 // operand2)

    # ???????????¨???
    print('{0}'.format(operand.pop()))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    opcode = []                 # ?????????????¨???¶??¨
    operand = []                # ?????´????¢??????????????¨???¶??¨

    # ??????????????\???
    while True:
        data = input()
        if data == '=':
            break
        elif data in '+-*/':
            opcode.append(data)
        else:
            if len(operand) == 0:
                operand.append(int(data))
            else:
                op = opcode.pop()
                operand1 = operand.pop()
                operand2 = int(data)
                if op == '+':
                    operand.append(operand1 + operand2)
                elif op == '-':
                    operand.append(operand1 - operand2)
                elif op == '*':
                    operand.append(operand1 * operand2)
                elif op == '/':
                    operand.append(operand1 // operand2)

    # ???????????¨???
    print('{0}'.format(operand.pop()))

Submission status: Accepted

Solution code:
ans=int(input())
while 1:
    n=input()
    if n=='=':
        print(ans)
        break
    a=int(input())
    if n=='+':ans+=a
    elif n=='-':ans-=a
    elif n=='*':ans*=a
    else: ans//=a

Submission status: Accepted

Solution code:
c = []
while True:
    s = input()
    if s=="=": break
    c.append(s)
ans = int(c[0])
for i in range(2, len(c), 2):
    o, v = c[i-1], int(c[i])
    if o=="+":
        ans += v
    elif o=="-":
        ans -= v
    elif o=="/":
        ans = ans // v
    else:
        ans *= v
print(ans)

Submission status: Accepted

Solution code:
import math
def main():
    a = []
    while 1:
        hoge = input()
        a.append(hoge)
        if hoge == "=":
            break

    cs = ["+", "-", "*", "/"]   #calculation symbol
    cs_i = []   #cs_index
    for x in range(len(a) - 1):
        if a[x] in cs:
            cs_i.append(x)
        else:
            a[x] = int(a[x])

    for x in range(len(cs_i)):
        if a[cs_i[x]] == "+":
            fuga = a[cs_i[x] - 1] + a[cs_i[x] + 1]
            a[cs_i[x] - 1] = a[cs_i[x]] = a[cs_i[x] + 1] = fuga
        elif a[cs_i[x]] == "-":
            fuga = a[cs_i[x] - 1] - a[cs_i[x] + 1]
            a[cs_i[x] - 1] = a[cs_i[x]] = a[cs_i[x] + 1] = fuga
        elif a[cs_i[x]] == "*":
            fuga = a[cs_i[x] - 1] * a[cs_i[x] + 1]
            a[cs_i[x] - 1] = a[cs_i[x]] = a[cs_i[x] + 1] = fuga
        elif a[cs_i[x]] == "/":
            fuga = a[cs_i[x] - 1] // a[cs_i[x] + 1]
            a[cs_i[x] - 1] = a[cs_i[x]] = a[cs_i[x] + 1] = int(fuga)

    print(a[cs_i[-1]])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
oper = True
po = ""
result = int(input())

while True:
    if oper:
        po = input()
        if po == "=":
            break
        oper = False
    else:
        inp = int(input())
        if po == "+":
            result += inp
        elif po == "-":
            result -= inp
        elif po == "*":
            result *= inp
        elif po == "/":
            result //= inp
        oper = True
print(result)

Submission status: Accepted

Solution code:
import sys

def pop(x):
    if(len(x) < 3):
        return str(int(0))
    a = x[len(x)-1]
    b = x[len(x)-2]
    c = x[len(x)-3]
    x[:] = list(x[:len(x)-3])
    if(b[0] == '+'):
        return str(int(float(a)) + int(float(c)))
    elif(b[0] == '-'):
        return str(int(float(c)) - int(float(a)))
    elif(b[0] == '*'):
        return str(int(float(a)) * int(float(c)))
    else:
        return str(int(float(c)) / int(float(a)))

l = []
for i in sys.stdin:
    l.append(i)
    if(len(l) == 3):
        l.append(pop(l))

print int(float(l[0]))

Submission status: Accepted

Solution code:
ans = int(input())
while 1:
    n = input()
    if n == '=':
        print(ans)
        break
    a = int(input())
    if n == '+': ans += a
    elif n == '-': ans -= a
    elif n == '*': ans *= a
    else: ans //= a

Submission status: Accepted

Solution code:
s=int(input())
while 1:
 o=input()
 if'='==o:break
 i=int(input())
 s={'+':s+i,'-':s-i,'*':s*i,'/':s//i}[o]
print(s)

Submission status: Accepted

Solution code:
n = int(input())
while True:
    s = input()
    if s == "-":
        n -= int(input())
    elif s == "+":
        n += int(input())
    elif s =="*":
        n *= int(input())
    elif s == "/":
        n = int(n/int(input()))
    else:
        print(n)
        break

Submission status: Accepted

Solution code:
def main():
  acc = int(input())
  while True:
    x = input()
    if x == "=":
      print(acc)
      break
    n = int(input())
    if x == "+":
      acc += n
    elif x == "-":
      acc -= n
    elif x == "*":
      acc *= n
    elif x == "/":
      acc //= n
main()

Submission status: Accepted

Solution code:
record = None
while True:
    x = input()
    if x == "=":
        break

    if x == "+" or x == "-" or x == "*" or x == "/":
        op = x
    elif record == None:
        record = x
    else:
        record = int(eval(str(record) + op + x))

print(record)

Submission status: Accepted

Solution code:
# coding=utf-8

if __name__ == '__main__':
    S = int(input())
    while True:
        inp = input()
        if inp == '=':
            print(S)
            break
        elif inp == '+':
            inp_number = int(input())
            S += inp_number
        elif inp == '-':
            inp_number = int(input())
            S -= inp_number
        elif inp == '*':
            inp_number = int(input())
            S *= inp_number
        elif inp == '/':
            inp_number = int(input())
            S //= inp_number

Submission status: Accepted

Solution code:
# AOJ 0588: Simple Calculator
# Python3 2018.6.30 bal4u

a = int(input())
while True:
	op = input().strip()
	if op == '=': break
	b = int(input()) 
	if   op == '+': a += b
	elif op == '-': a -= b
	elif op == '*': a *= b
	else:          a //= b
print(a)

Submission status: Accepted

Solution code:
res = input()
while True:
	s = raw_input()
	if s == '=': break
	x = input()
	if s == '/':
		res = abs(res) / abs(x) * cmp(res * x, 0)
	else:
		res = eval("res %s x" % s)
print res

Submission status: Accepted

Solution code:
(a, o) = ("", "")
while True:
  s = raw_input()
  if s == "=":
    break
  if s in ["+", "-", "*", "/"]:
    o = s
  else:
    a = eval(str(a) + o + s)
print a

Submission status: Accepted

Solution code:
a=input()
while True:
    c=raw_input()
    if c=="=":break
    b=input()
    if c=="+":
        a+=b
    elif c=="-":
        a-=b
    elif c=="*":
        a*=b
    elif c=="/":
        a/=b
print a

Submission status: Accepted

Solution code:
r, op = '',''
while True:
    s = raw_input()
    if s == '=':
        break
    if s in '+-*/':
        op = s
    else:
        r = eval('{0}{1}{2}'.format(r, op, s))
print r

Submission status: Accepted

Solution code:
ans = 0; buf = 0; c = 0;
func = {'+':lambda x, y : x+y,
        '-':lambda x, y : x-y,
        '*':lambda x, y : x*y,
        '/':lambda x, y : x//y
        }
while 1:
    if c==0:
        ans = int(raw_input())
    elif c%2==0:
        ans = func[buf](ans, int(raw_input()))
    else:
        buf = raw_input()
        if buf=='=':break
    c+=1
print ans

Submission status: Accepted

Solution code:

num = 0
b = "+"
while True:
  a = input()
  if b == "+":
    num += a
  elif b == "-":
    num -= a
  elif b == "*":
    num *= a
  elif b == "/":
    num /= a
  b = raw_input()
  if b == "=":
    print num
    break

Submission status: Accepted

Solution code:
e=input()
while 1:
	try:
		e=eval("e"+raw_input()+raw_input())
	except:
		break
print e

Submission status: Accepted

Solution code:
a = []
ans = 0
while 1:
    s = input()
    a.append(s)
    if s == "=" :
        break

ans = int(a[0])
for i in range(len(a)//2):
    if a[2*i + 1] == "+":
        ans += int(a[2*i +2])
    elif a[2*i + 1] == "-":
        ans -= int(a[2*i +2])
    elif a[2*i + 1] == "*":
        ans *= int(a[2*i +2])
    elif a[2*i + 1] == "/":
        ans //=int(a[2*i +2])
    elif a[2*i + 1] == "=":
        print(ans)

Submission status: Accepted

Solution code:
a = int(input())
while True:
    op = input()
    if op == "=":
        break
    b = int(input())
    if op == "+": a += b
    elif op == "-": a -= b
    elif op == "*": a *= b
    else: a //= b

print(a)

Submission status: Accepted

Solution code:
a = int(input())
while True:
  op = input()

  if op == "=":
    break
  b = int(input())
  if op == "+":
    a = a + b
  if op == "-":
    a = a - b
  if op == "*":
    a = a * b
  if op == "/":
    a = a // b
print(a)

Submission status: Accepted

Solution code:
s=[]
while True:
    tmp=input()
    if tmp=="=":
        break
    else:
        s.append(tmp)

ans=0
num=0
op=""
for i in range(len(s)):
    tmp=s[i]
    if i==0:
        num=int(tmp)
        ans=num
    elif i%2==0:
        num=int(tmp)
        if op=="+":
            ans+=num
        elif op=="-":
            ans-=num
        elif op=="*":
            ans*=num
        elif op=="/":
            ans//=num
    else:
        op=tmp

print(ans)

Submission status: Accepted

Solution code:
a=int(input())
while True:
    op=input()
    if op=="=":
        break
    b=int(input())
    if op=="+":
        a+=b
    elif op=="-":
        a-=b
    elif op=="*":
        a*=b
    elif op=="/":
        a//=b
    else:
        break
print(a)

Submission status: Accepted

Solution code:
x = int(input())
while True :
    calc = input()
    if calc == '=' :
        break
    y = int(input())
    
    if calc == '+' :
        x += y
    elif calc == '-' :
        x -= y
    elif calc == '*' :
        x *= y
    else :
        x = x // y
print(x)

Submission status: Accepted

Solution code:
ans = int(input())
while True:
    op = input()
    if op == '+':
        m = int(input())
        ans += m
    elif op == '-':
        m = int(input())
        ans -= m
    elif op == '*':
        m = int(input())
        ans *= m
    elif op == '/':
        m = int(input())
        ans //= m
    elif op == '=':
        print(ans)
        exit()

Submission status: Accepted

Solution code:
first = input()
while(True):
    operator = input()
    if operator == "=":
        break
    if operator == "/":
        operator = "//"
    second = input()
    first = str(eval(first + operator + second))

print(first)

Submission status: Accepted

Solution code:
# +, -, *, /, =
m = int(input())
while True:
	s = input()
	if s == '+':
		m = m + int(input())
	elif s == '-':
		m = m - int(input())
	elif s == '*':
		m = m * int(input())
	elif s == '/':
		m = m // int(input())
	elif s == '=':
		print(m)
		exit(0)

Submission status: Accepted

Solution code:
num_list = []
try:
    while True:
        num = input()
        num_list.append(num)
except EOFError:
    num = 0
finally:
    t = 1
    kei = int(num_list[0])
    num2 = len(num_list) / 2
    for num1 in range(int(num2)):
        if num_list[t] == "+":
            kei += int(num_list[t + 1])
        if num_list[t] == "-":
            kei -= int(num_list[t + 1])
        if num_list[t] == "*":
            kei *= int(num_list[t + 1])
        if num_list[t] == "/":
            kei /= int(num_list[t + 1])
            kei = int(kei)
        if num_list[t] == "=":
            print(kei)
        t += 2
        continue

Submission status: Accepted

Solution code:
ans = int(input())
while 1:
    op = input()
    if op == '=':
        print(ans)
        break
    n = int(input())
    if op == '+':
        ans += n
    elif op == '-':
        ans -= n
    elif op == '*':
        ans = ans*n
    else:
        ans = ans//n

Submission status: Accepted

Solution code:
a = int(input())
while 1:
    k = input()
    if k == '+':
        a += int(input())
    elif k == '-':
        a -= int(input())
    elif k == '*':
        a *= int(input())
    elif k == '/':
        a //= int(input())
    elif k == '=':
        print(a)
        break

Submission status: Accepted

Solution code:
def main():
    ans = int(input())
    op = input()
    while op != '=':
        b = int(input())
        if op == '+':
            ans += b
        elif op == '-':
            ans -= b
        elif op == '*':
            ans *= b
        elif op == '/':
            ans //= b
        op = input()
    else:
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = int(input())
while True:
    op = input().strip()
    if op == '=': break
    b = int(input()) 
    if   op == '+': a += b
    elif op == '-': a -= b
    elif op == '*': a *= b
    else:          a //= b
print(a)

Submission status: Accepted

Solution code:
n=int(input())
while 1:
    m=input()
    if m=="+":n+=int(input())
    elif m=="-":n-=int(input())
    elif m=="*":n*=int(input())
    elif m=="/":n//=int(input())
    elif m=="=":
        print(n)
        break

Submission status: Accepted

Solution code:
a = int(input())
while 1:
    calc = input()
    if calc == "=":
        break

    b = int(input())
    if calc == "+":
        a += b
    elif calc == "-":
        a -= b
    elif calc == "*":
        a *= b
    else:
        a //= b

print(a)

Submission status: Accepted

Solution code:
dat = "0"
s = []
while dat != "=":
    dat = input()
    s.append(dat)
ans = int(s[0])
for i in range(1,len(s)-2):
    if s[i] == "+":
        ans += int(s[i+1])
    elif s[i] == "-":
        ans -= int(s[i+1])
    elif s[i] == "*":
        ans *= int(s[i+1])
    elif s[i] == "/":
        ans //= int(s[i+1])
print(ans)

Submission status: Accepted

Solution code:
all = input()
while True:
  try:
    str = raw_input()
    if str == '=':
      print all
      break
    num = input()
    if str == '+':
      all += num
    elif str == '-':
      all -= num
    elif str == '*':
      all = all * num
    elif str == '/':
      all = all / num
  except EOFError:
    break

Submission status: Runtime Error

Solution code:
# AOJ 0588: Simple Calculator
# Python3 2018.6.30 bal4u

a = int(input())
while True:
	op = input().strip()
	if op == '=': break
	b = int(input()) 
	if      op == '+': a += b
	elif s == '-': a -= b
	elif s == '*': a *= b
	else:          a //= b
print(a)

Submission status: Runtime Error

Solution code:
a = 0
o = ""
while True:
  s = raw_input()
  if s == "=":
    break
  if s in ["+", "-", "*", "/"]:
    o = s
  else:
    a = eval(str(a) + o + s)
print a

Submission status: WA: Presentation Error

Solution code:
expr = "";
s = "";
while s != "=":
	s = raw_input();
	expr += s;

print "%d\n" % eval(expr[:-1])