s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1 value | original_language stringclasses 11 values | filename_ext stringclasses 1 value | status stringclasses 1 value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s971234213 | p00103 | u424041287 | 1507886427 | Python | Python3 | py | Runtime Error | 0 | 0 | 294 | a = int(input().rstrip())
b = 0
while a > b:
c = 0
runner = 0
point = 0
while c < 3:
x = input().rstrip()
if x == ???HIT???:
if runner == 3:
point += 1
else:
runner += 1
elif x == ???HOMERUN???:
point = point + runner + 1
runner = 0
else:
c += 1
print(point) |
s087038211 | p00103 | u424041287 | 1507886472 | Python | Python3 | py | Runtime Error | 0 | 0 | 286 | a = int(input().rstrip())
b = 0
while a > b:
c = 0
runner = 0
point = 0
while c < 3:
x = input().rstrip()
if x == "HIT":
if runner == 3:
point += 1
else:
runner += 1
elif x == "HOMERUN":
point = point + runner + 1
runner = 0
else:
c += 1
print(point) |
s142480475 | p00103 | u424041287 | 1507887220 | Python | Python3 | py | Runtime Error | 0 | 0 | 299 | a = int(input().rstrip())
b = 0
while a > b:
c = 0
runner = 0
point = 0
while c < 3:
x = str(input().rstrip())
if x == ???HIT???:
if runner == 3:
point += 1
else:
runner += 1
elif x == ???HOMERUN???:
point = point + runner + 1
runner = 0
else:
c += 1
print(point) |
s537841875 | p00103 | u150984829 | 1517478954 | Python | Python3 | py | Runtime Error | 0 | 0 | 170 | for _ in[0]*int(input()):
r=o=s=0
while 1:
a=input()[1]
if'I'==a:
if r<3:r+=1
else:s+=1
elif'O'==a:s+=r+1;r=0
else:
if r<3:o+=1
else:print(s);break
|
s902224045 | p00104 | u585391547 | 1412884635 | Python | Python3 | py | Runtime Error | 0 | 0 | 829 | def solve(IsTraveled,data,h,w):
IsTraveled[h][w]=True
x=data[h][w]
if x==".":
print(w,h)
elif x=="^":
if IsTraveled[h-1][w]==True:
print("LOOP")
else:
solve(IsTraveled,data,h-1,w)
elif x=="v":
if IsTraveled[h+1][w]==True:
print("LOOP")
else:
solve(IsTraveled,data,h+1,w)
elif x==">":
if IsTraveled[h][w+1]==True:
print("LOOP")
else:
solve(IsTraveled,data,h,w+1)
elif x=="<":
if IsTraveled[h][w-1]==True:
print("LOOP")
else:
solve(IsTraveled,data,h,w-1)
while 1:
y=input()
h,w=y.split()
h,w=int(h),int(w)
if h==0:
break
IsTraveled=[[False for i in range(w)] for j in range(h)]
data=[[] for j in range(h)]
for i in range(h):
inputdata=input()
for j in range(len(inputdata)):
data[i].append(inputdata[j])
solve(IsTraveled,data,0,0)
IsTraveled.clear()
data.clear() |
s215342305 | p00104 | u585391547 | 1412885311 | Python | Python3 | py | Runtime Error | 0 | 0 | 843 | def solve(IsTraveled,data,h,w):
IsTraveled[h][w]=True
x=data[h][w]
if x==".":
print(w,h)
elif x=="^":
if IsTraveled[h-1][w]==True:
print("LOOP")
else:
solve(IsTraveled,data,h-1,w)
elif x=="v":
if IsTraveled[h+1][w]==True:
print("LOOP")
else:
solve(IsTraveled,data,h+1,w)
elif x==">":
if IsTraveled[h][w+1]==True:
print("LOOP")
else:
solve(IsTraveled,data,h,w+1)
elif x=="<":
if IsTraveled[h][w-1]==True:
print("LOOP")
else:
solve(IsTraveled,data,h,w-1)
while 1:
y=input()
h,w=y.split()
h,w=int(h),int(w)
if h==0:
break
IsTraveled=[[False for i in range(w)] for j in range(h)]
data=[[] for j in range(h)]
for i in range(h):
inputdata=input()
for j in range(len(inputdata)):
data[i].append(inputdata[j])
# print(data)
solve(IsTraveled,data,0,0)
IsTraveled.clear()
data.clear() |
s562615871 | p00104 | u912237403 | 1414590665 | Python | Python | py | Runtime Error | 0 | 0 | 338 | def f():
A=[raw_input() for _ in range(h)]
x,y=0,0
while 1:
A[y]=A[y][0:x]+'x'+A[y][x+1:]
if s==">": x+=1
elif s=="<": x-=1
elif s=="v": y+=1
elif s=="^"3: y-=1
elif s==".": return " ".join(map(str,[x,y]))
else: return "LOOP"
while 1:
h,w=map(int,raw_input().split())
if h==w==0: break
print f() |
s925249403 | p00104 | u879226672 | 1424332270 | Python | Python | py | Runtime Error | 0 | 0 | 732 | def CurrentPos(ls,h=0,w=0):
if ls[h][w] == '>':
w +=1
elif ls[h][w] =='<':
w -=1
elif ls[h][w] =='^':
h -=1
elif ls[h][w] =='v':
h +=1
return [h,w]
def HasPosReached(pos_list,h,w):
for k,j in pos_list:
if (h,w) == (k,j):
return True
break
while True:
H,W = map(int, raw_input().split())
if [H,W] == [0,0]:
break
ls = []
for h in range(H):
ls.append(raw_input())
pos_list=[]
h =0; w=0
while True:
[h,w] = CurrentPos(ls,h,w)
pos_list.append((h,w))
if HasPosReached(h,w):
print "LOOP"
break
else:
print " ".join(map(str,[h,w])) |
s534108532 | p00104 | u040533857 | 1426052859 | Python | Python3 | py | Runtime Error | 0 | 0 | 296 | posX,posY=0,0
H,W=map(int,input())
for i in range(H):
spam=input().rstrip()
for j in range(W):
if posX==j:
if spam[j]=='>': posX+=1
elif spam[j]=='<': posX-=1
elif spam[j]=='v': posY+=1
elif spam[j]=='^': posY-=1
else: break |
s922474922 | p00104 | u040533857 | 1426055809 | Python | Python3 | py | Runtime Error | 0 | 0 | 659 | posX,posY=0,0
H,W=map(int,input().split())
while not(H==W==0):
tile=[[False for i in range(W)] for j in range(H)]
tileinfo=[['' for i in range(W)] for j in range(H)]
for i in range(H):
tileinfo[i]=input().rstrip()
while True:
if tileinfo[posX][posY]=='>': posX+=1
elif tileinfo[posX][posY]=='<': posX-=1
elif tileinfo[posX][posY]=='v':
posY+=1
break
elif tileinfo[posX][posY]=='^':
posY-=1
break
elif spam[j]=='.': break
if tile[posX][posY]==True:
print('LOOP')
break
else:
tile[posX][posY]=True |
s792529095 | p00104 | u040533857 | 1426056264 | Python | Python3 | py | Runtime Error | 0 | 0 | 717 | posX,posY=0,0
H,W=map(int,input().split())
while not(H==W==0):
tile=[[False for i in range(W)] for j in range(H)]
tileinfo=[['' for i in range(W)] for j in range(H)]
for i in range(H):
tileinfo[i]=input().rstrip()
while True:
if tileinfo[posX][posY]=='>':
posX+=1
elif tileinfo[posX][posY]=='<':
posX-=1
elif tileinfo[posX][posY]=='v':
posY+=1
elif tileinfo[posX][posY]=='^':
posY-=1
elif tileinfo[posX][posY]=='.':
print('{} {}'.format(posX,posY))
break
if tile[posX][posY]==True:
print('LOOP')
break
else:
tile[posX][posY]=True |
s436325472 | p00104 | u580607517 | 1427633794 | Python | Python | py | Runtime Error | 0 | 0 | 362 | while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0:
break
array = [[raw_input() for i in range(W)] for j in range(H)]
x = y = 0
while True:
w = array[x][y]
if w == ".":
print x, y
break
if w == ">":
x += 1
elif w == "v":
y += 1
elif w == "^":
y -= 1
elif w == "<":
x -= 1
else:
print "LOOP"
break |
s934431541 | p00104 | u580607517 | 1427634131 | Python | Python | py | Runtime Error | 0 | 0 | 381 | while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0:
break
tile = []
for i in range(H):
tile.append(list(raw_input()))
x = y = 0
while True:
a = tile[y][x]
tile[y][x] = 0
if w == ".":
print x, y
break
if w == ">":
x += 1
elif w == "v":
y += 1
elif w == "^":
y -= 1
elif w == "<":
x -= 1
else:
print "LOOP"
break |
s517119570 | p00104 | u580607517 | 1427634295 | Python | Python | py | Runtime Error | 0 | 0 | 377 | while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0:
break
tile = []
for i in range(H):
tile.append(list(raw_input()))
x = y = 0
while True:
a = tile[y][x]
tile[y][x] = 0
if w == ".":
print x, y;break
elif w == ">":
x += 1
elif w == "v":
y += 1
elif w == "^":
y -= 1
elif w == "<":
x -= 1
else:
print "LOOP";break |
s959422962 | p00104 | u472944603 | 1443505819 | Python | Python | py | Runtime Error | 0 | 0 | 711 | S = [["0" for i in range(10)] for j in range(10)]
while True:
check = [[False for i in range(10)] for j in range(10)]
x = 0
y = 0
LOOP = False
H, W = map(int, raw_input().split())
if (H == 0 and W == 0):
break
for i in range(H):
S[i] = raw_input()
while (S[y][x] != "."):
if (check[y][x] == True):
LOOP = True
print "LOOP"
break
check[y][x] = True
if (S[y][x] == "^"):
y -= 1
elif (S[y][x] == ">"):
x += 1
elif (S[y][x] == "v"):
y += 1
else:
x -= 1
if (LOOP == False):
print x, y |
s381838938 | p00104 | u301729341 | 1481992287 | Python | Python3 | py | Runtime Error | 0 | 0 | 643 | def moov(x,y):
if (x,y) in Loc:
return "LOOP"
else:
Loc.append((x,y))
if Room[y][x] == ".":
return str(x)+" "+str(y)
elif Room[y][x] == ">":
return moov(x + 1,y)
elif Room[y][x] == "<":
return moov(x - 1,y)
elif Room[y][x] == "^":
return moov(x,y - 1)
elif Room[y][x] == "v":
return moov(x,y + 1)
while True:
Loc = []
num = 0
Room = []
h,w = map(int,input().split())
if h == w == 0:
break
for i in range(h):
vec = input()
Room.append(list(vec))
print(moov(1,0)) |
s229852198 | p00104 | u301729341 | 1481992465 | Python | Python3 | py | Runtime Error | 0 | 0 | 631 | def moov(x,y):
if (x,y) in Loc:
return "LOOP"
else:
Loc.append((x,y))
if Room[y][x] == ".":
return str(x)+" "+str(y)
elif Room[y][x] == ">":
return moov(x + 1,y)
elif Room[y][x] == "<":
return moov(x - 1,y)
elif Room[y][x] == "^":
return moov(x,y - 1)
elif Room[y][x] == "v":
return moov(x,y + 1)
while True:
Loc = []
Room = []
h,w = map(int,input().split())
if h == w == 0:
break
for i in range(h):
vec = input()
Room.append(list(vec))
print(moov(1,0)) |
s963405717 | p00104 | u742505495 | 1510221949 | Python | Python | py | Runtime Error | 0 | 0 | 716 | import sys
import math
def decide_move(x,y,tile,check):
if tile == '<':
x -= 1
check[x][y] += 1
return x,y,check
elif tile == '>':
x += 1
check[x][y] += 1
return x,y,check
elif tile == '^':
y -= 1
check[x][y] += 1
return x,y,check
else:
y += 1
check[x][y] += 1
return x,y,check
while True:
h,w = map(int,input().split())
if h == 0:
break
tile_map = []
for i in range(h):
tile_map[i] = input()
check =[[0 for i in range(w)]for j in range(h)]
check[0][0] = 1
x = 0
y = 0
status = 0
while True:
if tile_map[x][y] == '.':
status = 1
print(y,x)
break
x,y,check = decide_move(x,y,tile_map[x][y],check)
if check[x][y] > 1:
status = 1
print('LOOP')
break |
s359300018 | p00104 | u742505495 | 1510222513 | Python | Python3 | py | Runtime Error | 0 | 0 | 719 | import sys
import math
def decide_move(x,y,tile,check):
if tile == '<':
x -= 1
check[x][y] += 1
return x,y,check
elif tile == '>':
x += 1
check[x][y] += 1
return x,y,check
elif tile == '^':
y -= 1
check[x][y] += 1
return x,y,check
else:
y += 1
check[x][y] += 1
return x,y,check
while True:
h,w = map(int,input().split())
if h == 0:
break
tile_map = []
for i in range(h):
tile_map.append(input())
check =[[0 for i in range(w)]for j in range(h)]
check[0][0] = 1
x = 0
y = 0
status = 0
while True:
if tile_map[x][y] == '.':
status = 1
print(y,x)
break
x,y,check = decide_move(x,y,tile_map[x][y],check)
if check[x][y] > 1:
status = 1
print('LOOP')
break |
s891679201 | p00104 | u009288816 | 1515236065 | Python | Python | py | Runtime Error | 0 | 0 | 975 | import sys
l = []
for input in sys.stdin:
l.append(input.split())
k = 0
res = []
matrix = []
while(k < len(l)):
for i in range(k+1,int(l[k][0])+1+k):
res.append(l[i][0])
for i in range(0,len(res)):
temp = []
for j in range(0,len(res[0])):
temp.append(res[i][j])
matrix.append(temp)
x = 0
y = 0
while(len(matrix) != 0 and matrix[y][x] != '.' and matrix[y][x] != 'x'):
if(matrix[y][x] == '>'):
matrix[y][x] = 'x'
x += 1
elif(matrix[y][x] == '<'):
matrix[y][x] = 'x'
x -= 1
elif(matrix[y][x] == 'v'):
matrix[y][x] = 'x'
y += 1
elif(matrix[y][x] == '^'):
matrix[y][x] = 'x'
y -= 1
if(int(l[k][0]) != 0 and int(l[k][1]) != 0):
if(matrix[y][x] == 'x'):
print 'LOOP'
else:
print x,y
del res[:]
del matrix[:]
k += int(l[k][0])+1
|
s412001467 | p00104 | u759934006 | 1372594158 | Python | Python | py | Runtime Error | 0 | 0 | 504 | DIR = {">": (0, 1), "<": (0, -1), "^": (-1, 0), "v": (1, 0)}
while True:
w, h = m(int, raw_input().split())
if w == 0 and h == 0:
break
m = []
for i in range(w):
m.append([c for c in raw_input().strip()])
x = 0
y = 0
while m[x][y] != '.':
i = m[x][y]
if i == 'x':
break
m[x][y] = 'x'
x += DIR[i][0]
y += DIR[i][1]
if m[x][y] == '.':
print("{} {}".format(y, x))
else:
print("LOOP") |
s241495377 | p00104 | u759934006 | 1372594330 | Python | Python | py | Runtime Error | 0 | 0 | 523 | DIR = {">": (0, 1), "<": (0, -1), "^": (-1, 0), "v": (1, 0)}
while True:
w, h = map(int, raw_input().split())
if w == 0 and h == 0:
break
m = [[] in i for range(w)]
for i in range(w):
m[i] = [c for c in raw_input().strip()]
x = 0
y = 0
while m[x][y] != '.':
i = m[x][y]
if i == 'x':
break
m[x][y] = 'x'
x += DIR[i][0]
y += DIR[i][1]
if m[x][y] == '.':
print("{} {}".format(y, x))
else:
print("LOOP") |
s251350554 | p00104 | u454358619 | 1377396909 | Python | Python | py | Runtime Error | 0 | 0 | 2489 | Last login: Sun Aug 25 10:28:39 on ttys002
-bash: /Users/yanzhao/Library/Enthought/Canopy_32bit/User/bin/activate: No such file or directory
yans-iMac:~ yanzhao$ ls
#del.py# Movies VirtualBox VMs
Desktop Music config.log
Documents MyProject.komodoproject del.py
Downloads Pictures del.py~
Library Public hpy.py
yans-iMac:~ yanzhao$ cd Documents/
yans-iMac:Documents yanzhao$ ls
Aizu cuda_5.0.36_macos-2.pkg
Aptana Rubles del.py
Aptana Studio 3 Workspace del.py~
C++ eclipse
Eworkspace ipython_study
Japaness opengl
Processing science.txt
PythonAlgorithms ubuntu-12.04.2-desktop-amd64.iso
QEMU ubuntu-12.04.2-desktop-i386.iso
QtTest unixstuff
Sale.py workspace
Sale.py~ yan.txt
c zhao.txt
cpp zhao.txt~
cs248Stanford
yans-iMac:Documents yanzhao$ cd Aizu
yans-iMac:Aizu yanzhao$ ls
Solution
yans-iMac:Aizu yanzhao$ cd Solution/
yans-iMac:Solution yanzhao$ ls
0009 0010 0102 0104
yans-iMac:Solution yanzhao$ cd 0104
yans-iMac:0104 yanzhao$ ls
#s.py# s.py s.py~
yans-iMac:0104 yanzhao$ emacs s.py
[1]+ Stopped emacs s.py
yans-iMac:0104 yanzhao$ emacs s.py
import sys
def UpSolve():
while True:
H,W = map(int ,raw_input().split())
if [H,W] == [0,0]:
return
else:
solve(H,W)
def solve(H,W):
# H,W = map( int,raw_input().split())
# if [H,W] == [0,0]:
# return
# print H,W
dmap = [ [[i,j,"",False] for i in range(W) ] for j in range(H)]
# print dmap
#read data
for j in range(H):
line = raw_input()
for i in range(W):
dmap[j][i][2] = line[i]
# print dmap
# print "########"
#end read data
#travel
tx,ty = 0,0
# while dmap[ty][tx][3] is not True:
-uu-:---F1 s.py Top L11 (Python)---------------------------------- |
s131526475 | p00104 | u633068244 | 1394016898 | Python | Python | py | Runtime Error | 0 | 0 | 463 | while True:
w, h = map(int, raw_input().split())
if w == 0 and h == 0:
break
tile = []
for i in range(h):
tile.append(list(raw_input()))
print tile
x = y = 0
while True:
a = tile[y][x]
tile[y][x] = 0
if a == ">": x += 1
elif a == "<": x -= 1
elif a == "^": y -= 1
elif a == "v": y += 1
elif a == ".": print x,y ; break
else: print "LOOP"; break |
s316247367 | p00104 | u633068244 | 1394017024 | Python | Python | py | Runtime Error | 0 | 0 | 467 | while True:
w, h = map(int, raw_input().split())
if w == 0 and h == 0:
break
tile = []
for i in range(h):
tile.append(list(raw_input()))
print tile
x = y = 0
while True:
a = tile[y][x]
tile[y][x] = 0
if a == ">": x += 1
elif a == "<": x -= 1
elif a == "^": y -= 1
elif a == "v": y += 1
elif a == ".": print x,y ; break
else: print "LOOP"; break |
s990850565 | p00104 | u633068244 | 1394017063 | Python | Python | py | Runtime Error | 0 | 0 | 453 | while True:
w, h = map(int, raw_input().split())
if w == 0 and h == 0:
break
tile = []
for i in range(h):
tile.append(list(raw_input()))
print tile
x = y = 0
while True:
a = tile[y][x]
tile[y][x] = 0
if a == ">": x += 1
elif a == "<": x -= 1
elif a == "^": y -= 1
elif a == "v": y += 1
elif a == ".": print x,y; break
else: print "LOOP"; break |
s554746896 | p00104 | u193025715 | 1398057685 | Python | Python | py | Runtime Error | 0 | 0 | 507 | while True:
h, w = map(int, raw_input().split())
if h + w == 0: break
b = [list(raw_input()) for i in range(h)]
direction = {'>':[1,0],'v':[0,1],'<':[-1,0],'^':[0,-1]}
f = False
for i in range(h):
for j in range(w):
if b[j][i] != ".":
p = [i,j]
f = True
break
if f: break
c = 0
while True:
tmp = direction[b[p[1]][p[0]]]
p[0] += tmp[0]
p[1] += tmp[1]
c += 1
if c == h * w:
print "LOOP"
break
elif b[p[1]][p[0]] == ".":
print "{} {}".format(p[0],p[1])
break |
s075205373 | p00104 | u193025715 | 1398057799 | Python | Python | py | Runtime Error | 0 | 0 | 507 | while True:
h, w = map(int, raw_input().split())
if h + w == 0: break
b = [list(raw_input()) for i in range(h)]
direction = {'>':[1,0],'v':[0,1],'<':[-1,0],'^':[0,-1]}
f = False
for i in range(h):
for j in range(w):
if b[j][i] != ".":
p = [i,j]
f = True
break
if f: break
c = 0
while True:
tmp = direction[b[p[1]][p[0]]]
p[0] += tmp[0]
p[1] += tmp[1]
c += 1
if c == h * w:
print "LOOP"
break
elif b[p[1]][p[0]] == ".":
print "{} {}".format(p[0],p[1])
break |
s391538847 | p00105 | u912237403 | 1414591929 | Python | Python | py | Runtime Error | 0 | 0 | 161 | d={}
for s in sys.stdin:
w,p=s.split()
if not w in d: d[w]=[]
d[w].append(int(p))
for w in sorted(d.keys()):
print w,"\n"," ".join(map(str,sorted(d[w]))) |
s028932088 | p00105 | u912237403 | 1414591973 | Python | Python | py | Runtime Error | 0 | 0 | 169 | d={}
for s in sys.stdin:
w,p=s.split()
if not w in d: d[w]=[]
d[w].append(int(p))
for w in sorted(d.keys()):
print w,"\n"
print " ".join(map(str,sorted(d[w]))) |
s472946762 | p00105 | u912237403 | 1414592022 | Python | Python | py | Runtime Error | 0 | 0 | 178 | d={}
for s in sys.stdin:
w,p=s.split()
if w in d: d[w].append(int(p))
else: d[w]=int(p)
for w in sorted(d.keys()):
print w,"\n"
print " ".join(map(str,sorted(d[w]))) |
s577986019 | p00105 | u755162050 | 1468838813 | Python | Python3 | py | Runtime Error | 0 | 0 | 452 | book_index = {}
while True:
try:
word, page = input().split(' ')
page = int(page)
page_list = book_index.get(word)
if page_list:
page_list.append(page)
else:
book_index[word] = [page]
except Exception:
break
for k in sorted(book_index.keys()):
print(k)
print(' '.join(map(str, (sorted(book_index.get(k)))))) |
s384837652 | p00105 | u546285759 | 1479465921 | Python | Python3 | py | Runtime Error | 0 | 0 | 285 | dic = {}
while True:
try:
word, pgn = input().split()
except ValueError:
break
if word in dic.keys():
dic[word].append(int(pgn))
else:
dic[word] = [int(pgn)]
for k, v in dic.items():
print(k)
print(' '.join(map(str, sorted(v)))) |
s370172250 | p00105 | u546285759 | 1479466098 | Python | Python3 | py | Runtime Error | 0 | 0 | 298 | dic = {}
while True:
try:
word, pgn = input().split()
if word in dic.keys():
dic[word].append(int(pgn))
else:
dic[word] = [int(pgn)]
except:
for k, v in dic.items():
print(k)
print(' '.join(map(str, sorted(v))))
break |
s425090652 | p00105 | u546285759 | 1479466254 | Python | Python3 | py | Runtime Error | 0 | 0 | 283 | dic = {}
while True:
try:
word, pgn = input().split()
if word in dic.keys():
dic[word].append(int(pgn))
else:
dic[word] = [int(pgn)]
except:
break
for k, v in dic.items():
print(k)
print(' '.join(map(str, sorted(v)))) |
s214109296 | p00105 | u503263570 | 1502043766 | Python | Python3 | py | Runtime Error | 0 | 0 | 183 | import sys
a={}
for i in sys.stdin:
b,c=i.split()
a.setdefault(b, []).append(c)
if c=='18':break
for a,b in sorted(a.items(), key=lambda x: x[0]):
print(a)
print(*b.sort()) |
s646194241 | p00105 | u742505495 | 1510281207 | Python | Python3 | py | Runtime Error | 0 | 0 | 408 | import sys
dic = {}
while True:
try:
a,b = map(str,input(),split())
page = int(b)
if a not in dic:
dic[a] = [page]
else:
dic[a].append(page)
except EOFError:
sorted(dic.keys())
names = list(dic.keys())
for i in range(len(names)):
print(names[i])
for j in range(len(dic[i])):
if j == len(dic[i])-1:
print(dic[i][j])
else:
sys.stdout.write(dic[i][j])
break |
s520461083 | p00105 | u633068244 | 1394007539 | Python | Python | py | Runtime Error | 0 | 0 | 222 | index = {}
while True:
try:
w, p = map(str, raw_input().split())
index.setdefault(w,[]).append(int(p))
index.sort()
for i in index:
index[i].sort()
print i
print " ".join(map(int, index[i])) |
s942442799 | p00106 | u811733736 | 1504448278 | Python | Python3 | py | Runtime Error | 0 | 0 | 1217 | def solve2(amount):
"""
???????¨???????????????¨?????????????????§???
"""
packages = [(0, 0), (2, 380), (3, 550), (5, 850), (10, 1520), (12, 1870), (15, 2244)] # 1?¢??????????(100g??????)??¨??????????????¢l
# dp??¨???2?¬??????????????¨?????????????(100g??????)?????????????????¨??§??????packages????¨????
# 999999...??????INF??¨?????? (phthon 3.5??\??????????????????math.inf????????¨??§??????)
cart = [[99999999] * (amount//100 + 1) for _ in range(len(packages))]
for i in range(len(packages)):
cart[i][0] = 0 # 0g???????????\????????´??????0???????????????
for i in range(1, len(packages)):
for j in range(1, len(cart[0])):
w = packages[i][0] # ??????
p = packages[i][1] # ??????
# ???????????????????????????????????????????????????????????????????????????????¨????
cart[i][j] = min(cart[i-1][j], cart[i-1][max(0, j-w)]+p, cart[i][max(0, j-w)]+p)
return cart[-1][-1]
def main(args):
while True:
amount = int(input())
if amount == 0:
break
result = solve2(amount)
print(result)
if __name__ == '__main__':
main(sys.argv[1:]) |
s928584706 | p00106 | u198069342 | 1511357492 | Python | Python3 | py | Runtime Error | 0 | 0 | 220 | h={15:2244,12:1870,10:1520,5:850,3:550,2:380}
m={0:0}
for i in range(50):
if i in m:
for k,v in h.items():
m[i+k] = min(m.get(i+k,1e9),m[i]+v)
while True:
n = input()
if n == 0 : break
print(m[n/100]) |
s168436260 | p00107 | u879226672 | 1424845968 | Python | Python | py | Runtime Error | 0 | 0 | 398 | def hantei(A,B,C,R=0):
h,t = sorted([A,B,C])[:2]
if h**2 + t**2 < 4 * R**2:
print 'OK'
else:
print 'NA'
while True:
try:
A,B,C = map(int,raw_input().split())
except EOFError:
break
for k in range(int(raw_input())):
hantei(A,B,C,int(raw_input()))
a,b,c = map(int,raw_input().split())
if (a,b,c) == (0,0,0):
break |
s426729983 | p00107 | u879226672 | 1424846252 | Python | Python | py | Runtime Error | 0 | 0 | 398 | def hantei(A,B,C,R=0):
h,t = sorted([A,B,C])[:2]
if h**2 + t**2 < 4 * R**2:
print 'OK'
else:
print 'NA'
while True:
try:
A,B,C = map(int,raw_input().split())
except EOFError:
break
for k in range(int(raw_input())):
hantei(A,B,C,int(raw_input()))
a,b,c = map(int,raw_input().split())
if (a,b,c) == (0,0,0):
break |
s998799283 | p00107 | u919202930 | 1488019994 | Python | Python3 | py | Runtime Error | 0 | 0 | 441 | def min_diag(A,B,C):
segments=[A,B,C]
segments.sort()
return (segments[0]**2+segments[1]**2)**(1/2)
while True:
# input one dataset
A,B,C = tuple(map(int,input().split()))
if (A,B,C) == (0,0,0):
break
n = int(input())
R = [None]*n
for i in range(n):
R[i] = int(input())
# process
min_diag = min_diag(A,B,C)
# judge & output
for r in R:
if min_diag < 2*r:
print("OK")
else:
print("NA") |
s105662170 | p00107 | u919202930 | 1488020121 | Python | Python3 | py | Runtime Error | 0 | 0 | 441 | def min_diag(A,B,C):
segments=[A,B,C]
segments.sort()
return (segments[0]**2+segments[1]**2)**(1/2)
while True:
# input one dataset
A,B,C = tuple(map(int,input().split()))
if (A,B,C) == (0,0,0):
break
n = int(input())
R = [None]*n
for i in range(n):
R[i] = int(input())
# process
min_diag = min_diag(A,B,C)
# judge & output
for r in R:
if min_diag < 2*r:
print("OK")
else:
print("NA") |
s405740184 | p00107 | u919202930 | 1488020306 | Python | Python3 | py | Runtime Error | 0 | 0 | 445 | def min_diag(A,B,C):
segments=[A,B,C]
segments.sort()
return (segments[0]**2+segments[1]**2)**(1/2)
while True:
# input one dataset
A,B,C = tuple(map(float,input().split()))
if (A,B,C) == (0,0,0):
break
n = int(input())
R = [None]*n
for i in range(n):
R[i] = float(input())
# process
min_diag = min_diag(A,B,C)
# judge & output
for r in R:
if min_diag < 2*r:
print("OK")
else:
print("NA") |
s735229368 | p00107 | u919202930 | 1488020569 | Python | Python3 | py | Runtime Error | 0 | 0 | 443 | def min_diag(A,B,C):
segments=[A,B,C]
segments.sort()
return (segments[0]**2+segments[1]**2)**(1/2)
while True:
# input one dataset
A,B,C = tuple(map(float,input().split()))
if (A,B,C) == (0,0,0):
break
n = int(input())
R = [None]*n
for i in range(n):
R[i] = float(input())
# process
min_diag = min_diag(A,B,C)
# judge & output
for r in R:
if min_diag < 2*r:
print("OK")
else:
print("NA") |
s350252286 | p00107 | u960312159 | 1508917982 | Python | Python3 | py | Runtime Error | 0 | 0 | 279 | while 1:
d, w, h = map(int, raw_input().split())
dmin = min(d**2 + w**2, w**2+h**2, h**2+d**2)
if dmin == 0:
break
n = input()
for i in range(n):
r = input()
if dmin < 2*r**2:
print 'OK'
else:
print 'NA' |
s590146039 | p00107 | u150984829 | 1517522203 | Python | Python3 | py | Runtime Error | 0 | 0 | 170 | import sys
for a in sys.stdin:
if'0'==a:break
s=list(map(int,input().split()))
c=0
while 1:
t=s;s=[t.count(e)for e in t]
if t==s:break
c+=1
print(c);print(*s)
|
s834701492 | p00107 | u847467233 | 1529191499 | Python | Python3 | py | Runtime Error | 0 | 0 | 279 | # AOJ 0107 Carry a Cheese
# Python3 2018.6.17 bal4u
while True:
d, w, h = list(map(int, input().split()))
if d == 0 and w == 0 and h == 0: break
min = min(d*d+w*w, d*d+h*h, w*w+h*h)
for _ in range(int(input())):
r = int(input())
print('OK' if min < (2*r)**2 else 'NA')
|
s802909353 | p00107 | u847467233 | 1529192118 | Python | Python3 | py | Runtime Error | 0 | 0 | 286 | # AOJ 0107 Carry a Cheese
# Python3 2018.6.17 bal4u
while True:
d, w, h = list(map(int, input().split()))
if d == 0 and w == 0 and h == 0: break
min = min(d*d+w*w, d*d+h*h, w*w+h*h)
n = int(input())
for i in range(n):
r = int(input())
print('OK' if (2*r)**2 > min else 'NA')
|
s397366641 | p00107 | u459861655 | 1353427939 | Python | Python | py | Runtime Error | 0 | 5648 | 438 | import math
i, size = 0, 0
rs = []
while True:
line = raw_input()
if line == '0 0 0':
for r in rs:
if size <= r:
print 'OK'
else:
print 'NA'
break
else:
i += 1
if i == 1:
t = [int(n) for n in line.split()]
t.sort()
size = int(math.ceil(math.sqrt(t[0] * t[0] + t[1] * t[1])))
if i > 2:
rs.append(int(line)) |
s292204406 | p00107 | u180584272 | 1379826760 | Python | Python | py | Runtime Error | 0 | 0 | 242 | from math import sqrt
cheeze = map(float,raw_input().split())
cheeze.sort()
supk = sqrt((cheeze[0]/2)**2 + (cheeze[1]/2)**2)
while True:
k = raw_input()
if k == "0 0 0": break
else:
k = int(k)
if k < supk: print "OK"
else: print "NA" |
s080246554 | p00107 | u180584272 | 1379837567 | Python | Python | py | Runtime Error | 0 | 0 | 278 | import sys
from math import sqrt
nyu = sys.stdin.read()
nyu = nyu.split("\n")
cheese = map(float,nyu[0].split())
cheese.sort()
supk = sqrt((cheese[0]/2)**2 + (cheese[1]/2)**2)
nyu = map(int,nyu[2:])
try:
for k in nyu:
if k < supk: print "OK"
else: print "NA"
except:
pass |
s877883129 | p00107 | u180584272 | 1379837593 | Python | Python | py | Runtime Error | 0 | 0 | 280 | import sys
from math import sqrt
nyu = sys.stdin.read()
nyu = nyu.split("\n")
cheese = map(float,nyu[0].split())
cheese.sort()
supk = sqrt((cheese[0]/2)**2 + (cheese[1]/2)**2)
nyu = map(int,nyu[2:-1])
try:
for k in nyu:
if k < supk: print "OK"
else: print "NA"
except:
pass |
s342575952 | p00108 | u350804311 | 1473283493 | Python | Python3 | py | Runtime Error | 0 | 0 | 358 | while True:
n = int(input())
if n == 0:
break
s = []
s = list(input().split())
while True:
t = []
u = 0
v = 0
for i in range(n):
for j in range(n):
if s[i] == s[j]:
u += 1
t.append(u)
t_str = list(map(str, t))
u = 0
if s == t:
print(str(v))
print(" ".join(t_str))
break
else:
s = t
v += 1 |
s836242269 | p00108 | u500396695 | 1478579249 | Python | Python3 | py | Runtime Error | 0 | 0 | 267 | def FOA(a, count):
b = a
for i in range(len(b)):
b[i] = a.count(a[i])
if b == a:
print(count)
print(" ".join(map(str, b)))
break
else:
return FOA(b, count + 1)
while True:
n = int(input())
if n == 0:
break
a = map(int, input().split())
FOA(a, 0) |
s026319180 | p00108 | u742505495 | 1512640384 | Python | Python3 | py | Runtime Error | 0 | 0 | 307 | import sys
while 1:
n=int(input())
if n==0:
break
s=list(int(input().split()))
cont=0
while 1:
tmp=[]
for i in range(n):
tmp[i]=[s.count(s[i])]
if s==temp:
print(cont)
break
else:
cont+=1
for i in range(n):
if i != n-1:
sys.stdout('{0} '.format(s[i]))
else:
print(s[i]) |
s241947646 | p00108 | u150984829 | 1517520990 | Python | Python3 | py | Runtime Error | 0 | 0 | 162 | while 1:
n=int(input())
if n:
s=list(map(int,input().split()))
c=0
while 1:
t=s;s=[t.count(e)for e in t]
if t==s:break
c+=1
print(c);print(*s)
|
s722833028 | p00109 | u471400255 | 1531277247 | Python | Python3 | py | Runtime Error | 0 | 0 | 1941 | 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,brac=None):
i = 0 # ループカウンタ?
num = deque() # 数字をためておく
ops = deque() # +-をためておく
ope = "" # */を保存
if not brac:
# 対応する括弧の位置を記録しておいて計算量を削減
brac = [-1 for j in range(len(exp))]
tmpbrac = []
for j in range(len(exp) - 1, 0, -1):
if exp[j] == ')':
tmpbrac.append(j)
elif exp[j] == '(':
brac[j] = tmpbrac.pop()
# かっこの中身と乗除算
while i < len(exp):
# かっこの中身は再帰的に計算
if exp[i] == '(':
num.append(calc(exp[i + 1:brac[i]],brac))
i = brac[i]
if ope:
r = num.pop()
l = 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 = "" # 数値 2桁以上にも対応させる
while i < len(exp) and exp[i].isnumeric():
temp += exp[i]
i += 1
i -= 1 # 最後の数字に戻る(最後にi+=1しているのでこれでいい)
num.append(int(temp))
if ope:
r = num.pop()
l = num.pop()
num.append(eva(l, r, ope))
ope = ""
i += 1
while len(ops) != 0:
num.appendleft(eva(num.popleft(),num.popleft(),ops.popleft()))
return num[0]
n = int(input())
for i in range(n):
exp = input()
print(calc(exp))
|
s263857037 | p00109 | u471400255 | 1531277421 | Python | Python3 | py | Runtime Error | 0 | 0 | 1942 | 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,brac=None):
i = 0 # ループカウンタ?
num = deque() # 数字をためておく
ops = deque() # +-をためておく
ope = "" # */を保存
if not brac:
# 対応する括弧の位置を記録しておいて計算量を削減
brac = [-1 for j in range(len(exp))]
tmpbrac = []
for j in range(len(exp) - 1, 0, -1):
if exp[j] == ')':
tmpbrac.append(j)
elif exp[j] == '(':
brac[j] = tmpbrac.pop()
# かっこの中身と乗除算
while i < len(exp):
# かっこの中身は再帰的に計算
if exp[i] == '(':
num.append(calc(exp[i + 1:brac[i]],brac))
i = brac[i]
if ope:
r = num.pop()
l = 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 = "" # 数値 2桁以上にも対応させる
while i < len(exp) and exp[i].isnumeric():
temp += exp[i]
i += 1
i -= 1 # 最後の数字に戻る(最後にi+=1しているのでこれでいい)
num.append(int(temp))
if ope:
r = num.pop()
l = num.pop()
num.append(eva(l, r, ope))
ope = ""
i += 1
while len(ops) != 0:
num.appendleft(eva(num.popleft(),num.popleft(),ops.popleft()))
return num[0]
n = int(input())
for i in range(n):
exp = input()
print(calc(exp))
|
s018045745 | p00109 | u471400255 | 1531278195 | Python | Python3 | py | Runtime Error | 0 | 0 | 1942 | 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,brac=None):
i = 0 # ループカウンタ?
num = deque() # 数字をためておく
ops = deque() # +-をためておく
ope = "" # */を保存
if not brac:
# 対応する括弧の位置を記録しておいて計算量を削減
brac = [-1 for j in range(len(exp))]
tmpbrac = []
for j in range(len(exp) - 1, 0, -1):
if exp[j] == ')':
tmpbrac.append(j)
elif exp[j] == '(':
brac[j] = tmpbrac.pop()
# かっこの中身と乗除算
while i < len(exp):
# かっこの中身は再帰的に計算
if exp[i] == '(':
num.append(calc(exp[i + 1:brac[i]],brac))
i = brac[i]
if ope:
r = num.pop()
l = 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 = "" # 数値 2桁以上にも対応させる
while i < len(exp) and exp[i].isnumeric():
temp += exp[i]
i += 1
i -= 1 # 最後の数字に戻る(最後にi+=1しているのでこれでいい)
num.append(int(temp))
if ope:
r = num.pop()
l = num.pop()
num.append(eva(l, r, ope))
ope = ""
i += 1
while len(ops) != 0:
num.appendleft(eva(num.popleft(),num.popleft(),ops.popleft()))
return num[0]
n = int(input())
for i in range(n):
exp = input()
print(calc(exp))
|
s540106571 | p00109 | u471400255 | 1531278366 | Python | Python3 | py | Runtime Error | 0 | 0 | 1951 | 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,brac=None):
i = 0 # ループカウンタ?
num = deque() # 数字をためておく
ops = deque() # +-をためておく
ope = "" # */を保存
if not brac:
# 対応する括弧の位置を記録しておいて計算量を削減
brac = [-1 for j in range(len(exp))]
tmpbrac = []
for j in range(len(exp) - 1, 0, -1):
if exp[j] == ')':
tmpbrac.append(j)
elif exp[j] == '(':
brac[j] = tmpbrac.pop()
# かっこの中身と乗除算
while i < len(exp):
# かっこの中身は再帰的に計算
if exp[i] == '(':
num.append(calc(exp[i + 1:brac[i]],brac))
i = brac[i]
if ope:
r = num.pop()
l = 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 = exp[i] # 数値 2桁以上にも対応させる
i += 1
while i < len(exp) and exp[i].isnumeric():
temp += exp[i]
i += 1
i -= 1 # 最後の数字に戻る(最後にi+=1しているのでこれでいい)
num.append(int(temp))
if ope:
r = num.pop()
l = num.pop()
num.append(eva(l, r, ope))
ope = ""
i += 1
while len(ops) != 0:
num.appendleft(eva(num.popleft(),num.popleft(),ops.popleft()))
return num[0]
n = int(input())
for i in range(n):
print(calc(input()))
|
s366906723 | p00109 | u858885710 | 1406319604 | Python | Python | py | Runtime Error | 0 | 0 | 77 | for _ in range( int(raw_input()) ): print int(eval( "1.0"+raw_input()[:-1] )) |
s841685600 | p00109 | u912237403 | 1414795805 | Python | Python | py | Runtime Error | 0 | 0 | 858 | 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) |
s585153471 | p00109 | u633068244 | 1425019325 | Python | Python | py | Runtime Error | 0 | 0 | 89 | N = int(raw_input())
for loop in xrange(N):
print eval(raw_input().replace("/","//")) |
s331536662 | p00109 | u379499530 | 1432280295 | Python | Python | py | Runtime Error | 0 | 0 | 1036 | ops = {"+": lambda a, b: b + a,
"-": lambda a, b: b - a,
"*": lambda a, b: b * a,
"/": lambda a, b: b // a}
def calc(temp, v):
if v in ops:
temp.append(ops[v](temp.pop(), temp.pop()))
else:
temp.append(int(v))
return temp
n = input()
for i in range(n):
porand = []
temp = []
formula = raw_input()
for j in formula:
if j >= "0" and j <= "9": porand.append(j)
elif (j == "*" or j == "/") or j == "(": temp.append(j)
elif j == "+" or j == "-":
if len(temp) > 0:
for k in reversed(temp):
if k == "*" or k == "/": porand.append(temp.pop())
else: break
temp.append(j)
elif j == ")":
for k in reversed(temp):
if k == "(":
temp.pop()
break
porand.append(temp.pop())
elif j == "=":
for k in reversed(temp): porand.append(k)
print reduce(calc, porand, [])[-1] |
s481802056 | p00109 | u379499530 | 1432280374 | Python | Python | py | Runtime Error | 0 | 0 | 1035 | ops = {"+": lambda a, b: b + a,
"-": lambda a, b: b - a,
"*": lambda a, b: b * a,
"/": lambda a, b: b / a}
def calc(temp, v):
if v in ops:
temp.append(ops[v](temp.pop(), temp.pop()))
else:
temp.append(int(v))
return temp
n = input()
for i in range(n):
porand = []
temp = []
formula = raw_input()
for j in formula:
if j >= "0" and j <= "9": porand.append(j)
elif (j == "*" or j == "/") or j == "(": temp.append(j)
elif j == "+" or j == "-":
if len(temp) > 0:
for k in reversed(temp):
if k == "*" or k == "/": porand.append(temp.pop())
else: break
temp.append(j)
elif j == ")":
for k in reversed(temp):
if k == "(":
temp.pop()
break
porand.append(temp.pop())
elif j == "=":
for k in reversed(temp): porand.append(k)
print reduce(calc, porand, [])[-1] |
s920838947 | p00109 | u379499530 | 1432281309 | Python | Python | py | Runtime Error | 0 | 0 | 1258 | ops = {"+": lambda a, b: b + a,
"-": lambda a, b: b - a,
"*": lambda a, b: b * a,
"/": lambda a, b: b / a,
"@": lambda a, b: -(abs(int(1.0*a/b)))}
def calc(temp, v):
if v in ["+", "-", "*"]:
temp.append(ops[v](temp.pop(), temp.pop()))
elif v == "/":
if temp[-1] < 0 or temp[-2] < 0: temp.append(ops["@"](temp.pop(), temp.pop()))
else: temp.append(ops[v](temp.pop(), temp.pop()))
else:
temp.append(int(v))
return temp
n = input()
for i in range(n):
porand = []
temp = []
formula = raw_input()
for j in formula:
if j >= "0" and j <= "9": porand.append(j)
elif (j == "*" or j == "/") or j == "(": temp.append(j)
elif j == "+" or j == "-":
if len(temp) > 0:
for k in reversed(temp):
if k == "*" or k == "/": porand.append(temp.pop())
else: break
temp.append(j)
elif j == ")":
for k in reversed(temp):
if k == "(":
temp.pop()
break
porand.append(temp.pop())
elif j == "=":
for k in reversed(temp): porand.append(k)
print reduce(calc, porand, [])[-1] |
s521814293 | p00109 | u379499530 | 1432283288 | Python | Python | py | Runtime Error | 0 | 0 | 1405 | ops = {"+": lambda a, b: b + a,
"-": lambda a, b: b - a,
"*": lambda a, b: b * a,
"/": lambda a, b: b / a,
"@": lambda a, b: -(abs(int(1.0*b/a)))}
def calc(stack, v):
if v in ["+", "-", "*"]:
stack.append(ops[v](stack.pop(), stack.pop()))
elif v == "/":
if stack[-1] < 0 or stack[-2] < 0: stack.append(ops["@"](stack.pop(), stack.pop()))
else: stack.append(ops[v](stack.pop(), stack.pop()))
else:
stack.append(int(v))
return stack
n = input()
for i in range(n):
porand = []
temp = []
stack = []
formula = raw_input()
for j in formula:
if j >= "0" and j <= "9": porand.append(j)
elif (j == "*" or j == "/") or j == "(": stack.append(j)
elif j == "+" or j == "-":
if len(stack) > 0:
for k in reversed(stack):
if k == "*" or k == "/": temp.append(stack.pop())
else:
porand.extend(temp)
temp = []
break
temp.append(j)
elif j == ")":
for k in reversed(stack):
if k == "(":
porand.extend(temp)
stack.pop()
break
else: temp.append(stack.pop())
elif j == "=": porand.extend(stack)
print reduce(calc, porand, [])[-1] |
s333212283 | p00109 | u873482706 | 1435238675 | Python | Python | py | Runtime Error | 0 | 0 | 1827 | 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 = []
for c in gemstone:
if c.isdigit():
n += c
else:
lis.append(n)
lis.append(c)
n = ''
else:
lis.append(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
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) |
s446352414 | p00109 | u873482706 | 1435239293 | Python | Python | py | Runtime Error | 0 | 0 | 1830 | 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 = []
for c in gemstone:
if c.isdigit():
n += c
else:
lis.append(n)
lis.append(c)
n = ''
else:
lis.append(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
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('=\\n')
up_to_you(formula) |
s687508870 | p00109 | u873482706 | 1435240983 | Python | Python | py | Runtime Error | 0 | 0 | 1827 | 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 = []
for c in gemstone:
if c.isdigit():
n += c
else:
lis.append(n)
lis.append(c)
n = ''
else:
lis.append(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
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) |
s393635138 | p00109 | u873482706 | 1435242232 | Python | Python | py | Runtime Error | 0 | 0 | 1784 | 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 = []
for c in gemstone:
if c.isdigit():
n += c
else:
lis.append(n)
lis.append(c)
n = ''
else:
lis.append(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
elif o == '+':
r = o1 + o2
elif o == '-':
r = o1 - o2
return str(r)
N = int(raw_input())
for i in range(N):
formula = raw_input().rstrip('=')
up_to_you(formula) |
s438264538 | p00109 | u873482706 | 1435243220 | Python | Python | py | Runtime Error | 0 | 0 | 1872 | 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 = []
for c in gemstone:
if c.isdigit():
n += c
else:
lis.append(n)
lis.append(c)
n = ''
else:
lis.append(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
elif o == '+':
r = o1 + o2
elif o == '-':
r = o1 - o2
return str(r)
while True:
try:
N = int(raw_input())
for i in range(N):
formula = raw_input().rstrip('=')
up_to_you(formula)
except EOFError:
break |
s986941801 | p00109 | u873482706 | 1435244375 | Python | Python | py | Runtime Error | 0 | 0 | 1823 | 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 int(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 = []
for c in gemstone:
if c.isdigit():
n += c
else:
lis.append(n)
lis.append(c)
n = ''
else:
lis.append(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
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) |
s274467754 | p00109 | u873482706 | 1435289194 | Python | Python | py | Runtime Error | 0 | 0 | 1818 | 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 = []
for c in gemstone:
if c.isdigit():
n += c
else:
lis.append(n)
lis.append(c)
n = ''
else:
lis.append(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
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) |
s211180156 | p00109 | u873482706 | 1435298924 | Python | Python | py | Runtime Error | 0 | 0 | 1963 | 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:
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) |
s773755072 | p00109 | u180584272 | 1436083796 | Python | Python3 | py | Runtime Error | 0 | 0 | 824 | 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(int(calc(raw_input()[:-1])))
main() |
s619365812 | p00109 | u180584272 | 1436140323 | Python | Python | py | Runtime Error | 0 | 0 | 738 | 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 test(raw_input()[:-1])
main() |
s896865028 | p00109 | u180584272 | 1436140692 | Python | Python | py | Runtime Error | 0 | 0 | 775 | 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()
#?????????WA?????? |
s816895999 | p00109 | u077582668 | 1445773691 | Python | Python | py | Runtime Error | 0 | 0 | 2166 | import sys
#while 1:
# (a,b,c) = map(int , raw_input().split())
def isdigit2(n):
n = str(n)
if(n.isdigit()):return True
if(n.startwith("-")):
if(len(n)==1):return False
if(str(n)[1:].isdigit):return True
return False
def parse(line):
lis = []
ind =0
while(line[ind]!="="):
a = line[ind]
if(a.isdigit()==False):
lis.append(a)
ind+=1
continue
else:
s=ind
while(line[ind].isdigit()):ind+=1
lis.append(line[s:ind])
continue
return lis
def dParen(lis,sind):
cnt = 1
s = sind
sind+=1
while 1:
if(lis[sind]==")"):
cnt -= 1
if(cnt==0):return (s,sind)
elif(lis[sind]=="("):
cnt += 1
sind+=1
def eva(lis):
#print lis
if(len(lis)==1):return lis[0]
if("(" in lis):
(s,e) = dParen(lis,lis.index("("))
val = eva(lis[s+1:e])
lis[s:e+1]=[val]
return eva(lis)
if("*" in lis or "/" in lis):
inmin = 0;
if(("*" in lis)==False):
inmin = lis.index("/")
elif(("/" in lis)==False):
inmin = lis.index("*")
else:
inmin = min(lis.index("x"),lis.index("/"))
if(lis[inmin]=="*"):
val = int(lis[inmin-1])*int(lis[inmin+1])
lis[inmin-1:inmin+2]=[val]
else:
val = int(lis[inmin-1])/int(lis[inmin+1])
lis[inmin-1:inmin+2]=[val]
return eva(lis)
if("+" in lis or "-" in lis):
if(("+" in lis)==False):
inmin = lis.index("-")
elif(("-" in lis)==False):
inmin = lis.index("+")
else:
inmin = min(lis.index("+"),lis.index("-"))
if(lis[inmin]=="+"):
val = int(lis[inmin-1])+int(lis[inmin+1])
lis[inmin-1:inmin+2]= [val]
else:
val = int(lis[inmin-1])-int(lis[inmin+1])
lis[inmin-1:inmin+2]=[val]
return eva(lis)
n = int(raw_input())
for i in range(n):
calcu = parse(raw_input())
#print calcu
print eva(calcu) |
s359850737 | p00109 | u077582668 | 1445773939 | Python | Python | py | Runtime Error | 0 | 0 | 1908 | def parse(line):
lis = []
ind =0
while(line[ind]!="="):
a = line[ind]
if(a.isdigit()==False):
lis.append(a)
ind+=1
continue
else:
s=ind
while(line[ind].isdigit()):ind+=1
lis.append(line[s:ind])
continue
return lis
def dParen(lis,sind):
cnt = 1
s = sind
sind+=1
while 1:
if(lis[sind]==")"):
cnt -= 1
if(cnt==0):return (s,sind)
elif(lis[sind]=="("):
cnt += 1
sind+=1
def eva(lis):
#print lis
if(len(lis)==1):return lis[0]
if("(" in lis):
(s,e) = dParen(lis,lis.index("("))
val = eva(lis[s+1:e])
lis[s:e+1]=[val]
return eva(lis)
if("*" in lis or "/" in lis):
inmin = 0;
if(("*" in lis)==False):
inmin = lis.index("/")
elif(("/" in lis)==False):
inmin = lis.index("*")
else:
inmin = min(lis.index("x"),lis.index("/"))
if(lis[inmin]=="*"):
val = int(lis[inmin-1])*int(lis[inmin+1])
lis[inmin-1:inmin+2]=[val]
else:
val = int(lis[inmin-1])/int(lis[inmin+1])
lis[inmin-1:inmin+2]=[val]
return eva(lis)
if("+" in lis or "-" in lis):
if(("+" in lis)==False):
inmin = lis.index("-")
elif(("-" in lis)==False):
inmin = lis.index("+")
else:
inmin = min(lis.index("+"),lis.index("-"))
if(lis[inmin]=="+"):
val = int(lis[inmin-1])+int(lis[inmin+1])
lis[inmin-1:inmin+2]= [val]
else:
val = int(lis[inmin-1])-int(lis[inmin+1])
lis[inmin-1:inmin+2]=[val]
return eva(lis)
n = int(raw_input())
for i in range(n):
calcu = parse(raw_input())
#print calcu
print eva(calcu) |
s955459091 | p00109 | u077582668 | 1445774292 | Python | Python | py | Runtime Error | 0 | 0 | 2087 |
def parse(line):
lis = []
ind =0
while(line[ind]!="="):
a = line[ind]
if(ind==0 and a=="-"):
s=ind
ind += 1
while(line[ind].isdigit()):ind+=1
lis.append(int(line[s:ind]))
continue
if(a.isdigit()==False):
lis.append(a)
ind+=1
continue
else:
s=ind
while(line[ind].isdigit()):ind+=1
lis.append(line[s:ind])
continue
return lis
def dParen(lis,sind):
cnt = 1
s = sind
sind+=1
while 1:
if(lis[sind]==")"):
cnt -= 1
if(cnt==0):return (s,sind)
elif(lis[sind]=="("):
cnt += 1
sind+=1
def eva(lis):
#print lis
if(len(lis)==1):return lis[0]
if("(" in lis):
(s,e) = dParen(lis,lis.index("("))
val = eva(lis[s+1:e])
lis[s:e+1]=[val]
return eva(lis)
if("*" in lis or "/" in lis):
inmin = 0;
if(("*" in lis)==False):
inmin = lis.index("/")
elif(("/" in lis)==False):
inmin = lis.index("*")
else:
inmin = min(lis.index("x"),lis.index("/"))
if(lis[inmin]=="*"):
val = int(lis[inmin-1])*int(lis[inmin+1])
lis[inmin-1:inmin+2]=[val]
else:
val = int(lis[inmin-1])/int(lis[inmin+1])
lis[inmin-1:inmin+2]=[val]
return eva(lis)
if("+" in lis or "-" in lis):
if(("+" in lis)==False):
inmin = lis.index("-")
elif(("-" in lis)==False):
inmin = lis.index("+")
else:
inmin = min(lis.index("+"),lis.index("-"))
if(lis[inmin]=="+"):
val = int(lis[inmin-1])+int(lis[inmin+1])
lis[inmin-1:inmin+2]= [val]
else:
val = int(lis[inmin-1])-int(lis[inmin+1])
lis[inmin-1:inmin+2]=[val]
return eva(lis)
n = int(raw_input())
for i in range(n):
calcu = parse(raw_input())
#print calcu
print eva(calcu) |
s071894126 | p00109 | u529386725 | 1459659805 | Python | Python3 | py | Runtime Error | 0 | 0 | 1993 | # ????????±?????¬??§??????????????????[l, r)??§??????
def getLR(li):
l, r = 0, 0
for i in range(len(li)):
if li[i] == "(":
l = i
if li[i] == ")":
r = i + 1
return l, r
return l, r
# li????¨?????????????????????????(li?????¬??§???????????????)
def calc(li):
# *, / ?????????
t_li = []
while True:
for i in range(len(li) - 2):
if li[i + 1] == "*":
t_li = li[:i] + [li[i] * li[i + 2]] + li[i + 3:]
li = list(t_li)
break
elif li[i + 1] == "/":
t_li = li[:i] + [li[i] // li[i + 2]] + li[i + 3:]
li = list(t_li)
break
else:
# ??´??°??????????????°????????????????????????
break
# +, - ?????????
while True:
for i in range(len(li) - 2):
if li[i + 1] == "+":
t_li = li[:i] + [li[i] + li[i + 2]] + li[i + 3:]
li = list(t_li)
break
elif li[i + 1] == "-":
t_li = li[:i] + [li[i] - li[i + 2]] + li[i + 3:]
li = list(t_li)
break
else:
# ??´??°??????????????°????????????????????????
break
return t_li
n = int(input())
for _ in range(n):
s = input()[:-1]
# ??°?????¨?¨????????????????????????? ("#"?????????)
s = "#(" + s + ")#"
li = []
number = ""
for i in range(len(s)):
if s[i].isdigit():
number += s[i]
else:
if number != "":
li.append(int(number))
number = ""
li.append(s[i])
# ??¬??§??????????????±?????¨??????????????????????????????
while True:
# print(li)
l, r = getLR(li)
# ??¬??§????????????????????°??????
if r == 0:
break
li = li[:l] + calc(li[l + 1 : r - 1]) + li[r:]
print(li[1]) |
s459740174 | p00109 | u529386725 | 1459659911 | Python | Python3 | py | Runtime Error | 0 | 0 | 1551 | def getLR(li):
l, r = 0, 0
for i in range(len(li)):
if li[i] == "(":
l = i
if li[i] == ")":
r = i + 1
return l, r
return l, r
def calc(li):
# *, /
t_li = []
while True:
for i in range(len(li) - 2):
if li[i + 1] == "*":
t_li = li[:i] + [li[i] * li[i + 2]] + li[i + 3:]
li = list(t_li)
break
elif li[i + 1] == "/":
t_li = li[:i] + [li[i] // li[i + 2]] + li[i + 3:]
li = list(t_li)
break
else:
# no update
break
# +, -
while True:
for i in range(len(li) - 2):
if li[i + 1] == "+":
t_li = li[:i] + [li[i] + li[i + 2]] + li[i + 3:]
li = list(t_li)
break
elif li[i + 1] == "-":
t_li = li[:i] + [li[i] - li[i + 2]] + li[i + 3:]
li = list(t_li)
break
else:
break
return t_li
n = int(input())
for _ in range(n):
s = input()[:-1]
s = "#(" + s + ")#"
li = []
number = ""
for i in range(len(s)):
if s[i].isdigit():
number += s[i]
else:
if number != "":
li.append(int(number))
number = ""
li.append(s[i])
while True:
l, r = getLR(li)
if r == 0:
break
li = li[:l] + calc(li[l + 1 : r - 1]) + li[r:]
print(li[1]) |
s827224095 | p00109 | u873482706 | 1460424990 | Python | Python3 | py | Runtime Error | 0 | 0 | 1425 | def f1(line):
p = None
q = None
for i, s in enumerate(line):
if s == '(':
p = i
elif s == ')':
q = i
if q:
break
else:
return f2(line)
before = line[:p]
after = line[q + 1:]
x = f2(line[p + 1:q])
return f1(before + str(x) + after)
def f2(f_line):
foo = []
digit = ''
for x in f_line:
if x.isdigit():
digit += x
else:
foo.append(int(digit))
foo.append(x)
digit = ''
foo.append(int(digit))
return f3(foo, 'first')
def f3(foo, flg):
if len(foo) == 1:
return foo[0]
target = None
for i, fo in enumerate(foo):
if flg == 'first':
target = f4(foo, fo, i)
elif flg == 'second':
target = f5(foo, fo, i)
if target:
break
else:
flg = 'second'
return f3(foo, flg)
foo = foo[:i-1] + [target] + foo[i+2:]
return f3(foo, flg)
def f4(foo, fo, i):
target = None
if fo == '*':
target = foo[i-1] * foo[i+1]
elif fo == '/':
target = int(foo[i-1] / foo[i+1])
return target
def f5(foo, fo, i):
target = None
if fo == '+':
target = foo[i-1] + foo[i+1]
elif fo == '-':
target = int(foo[i-1] - foo[i+1])
return target
for _ in range(int(input())):
ans = f1(input())
print(ans) |
s071474144 | p00109 | u873482706 | 1460425047 | Python | Python3 | py | Runtime Error | 0 | 0 | 1458 | def f1(line):
p = None
q = None
for i, s in enumerate(line):
if s == '(':
p = i
elif s == ')':
q = i
if q:
break
else:
return f2(line)
before = line[:p]
after = line[q + 1:]
x = f2(line[p + 1:q])
return f1(before + str(x) + after)
def f2(f_line):
foo = []
digit = ''
for x in f_line:
if x.isdigit():
digit += x
else:
foo.append(int(digit))
foo.append(x)
digit = ''
foo.append(int(digit))
return f3(foo, 'first')
def f3(foo, flg):
if len(foo) == 1:
return foo[0]
target = None
for i, fo in enumerate(foo):
if flg == 'first':
target = f4(foo, fo, i)
elif flg == 'second':
target = f5(foo, fo, i)
if target:
break
else:
flg = 'second'
return f3(foo, flg)
foo = foo[:i-1] + [target] + foo[i+2:]
return f3(foo, flg)
def f4(foo, fo, i):
target = None
if fo == '*':
target = foo[i-1] * foo[i+1]
elif fo == '/':
target = int(foo[i-1] / foo[i+1])
return target
def f5(foo, fo, i):
target = None
if fo == '+':
target = foo[i-1] + foo[i+1]
elif fo == '-':
target = int(foo[i-1] - foo[i+1])
return target
for _ in range(int(input())):
input_line = input()
ans = f1(input_line[:-1])
print(ans) |
s410795361 | p00109 | u873482706 | 1460445473 | Python | Python3 | py | Runtime Error | 0 | 0 | 1425 | def f1(line):
p = None
q = None
for i, s in enumerate(line):
if s == '(':
p = i
elif s == ')':
q = i
if q:
break
else:
return f2(line)
before = line[:p]
after = line[q + 1:]
x = f2(line[p + 1:q])
return f1(before + str(x) + after)
def f2(f_line):
foo = []
digit = ''
for x in f_line:
if x.isdigit():
digit += x
else:
foo.append(int(digit))
foo.append(x)
digit = ''
foo.append(int(digit))
return f3(foo, 'first')
def f3(foo, flg):
if len(foo) == 1:
return foo[0]
target = None
for i, fo in enumerate(foo):
if flg == 'first':
target = f4(foo, fo, i)
elif flg == 'second':
target = f5(foo, fo, i)
if target:
break
else:
flg = 'second'
return f3(foo, flg)
foo = foo[:i-1] + [target] + foo[i+2:]
return f3(foo, flg)
def f4(foo, fo, i):
target = None
if fo == '*':
target = foo[i-1] * foo[i+1]
elif fo == '/':
target = int(foo[i-1] / foo[i+1])
return target
def f5(foo, fo, i):
target = None
if fo == '+':
target = foo[i-1] + foo[i+1]
elif fo == '-':
target = foo[i-1] - foo[i+1]
return target
for _ in range(int(input())):
ans = f1(input()[:-1])
print(ans) |
s538659080 | p00109 | u630224637 | 1479208225 | Python | Python | py | Runtime Error | 0 | 0 | 65 |
n = int(input())
for i in range(n):
s = input()
print(s) |
s544155368 | p00109 | u919202930 | 1481684187 | Python | Python3 | py | Runtime Error | 0 | 0 | 416 | inputs=[]
while True:
try:
inputs.append(input())
except EOFError:
break
for i in inputs:
a,c=i.split("=")
a,b=a.split("+")
# a+b=c
for x in range(0,10):
if x==0 and (a[0]=="X" or b[0]=="X" or c[0]=="X"):
next
A=a.replace("X",str(x))
B=b.replace("X",str(x))
C=c.replace("X",str(x))
if int(A)+int(B)==int(C):
print(x)
break
if x == 9:
print("NA") |
s150138173 | p00109 | u919202930 | 1482208951 | Python | Python3 | py | Runtime Error | 0 | 0 | 838 | 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)
datasets=[]
while True:
try:
datasets.append(input())
except EOFError:
break
for line in datasets:
if line[-1] != '=':
continue
else:
l = line.split("=",maxsplit=1)[0]
print(unfold_brackets(l)) |
s291368837 | p00109 | u919202930 | 1482209219 | Python | Python3 | py | Runtime Error | 0 | 0 | 754 | 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)
n=int(input())
datasets=[input() for i in range(n)]
for line in datasets:
l = line.split("=",maxsplit=1)[0]
print(unfold_brackets(l)) |
s458525134 | p00109 | u919202930 | 1482210923 | Python | Python3 | py | Runtime Error | 0 | 0 | 780 | 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)
n=int(input())
datasets=[None]*n
for i in range(0,n):
datasets[i] = input()
for line in datasets:
l = line.split("=",maxsplit=1)[0]
print(unfold_brackets(l)) |
s532557615 | p00109 | u919202930 | 1482232962 | Python | Python3 | py | Runtime Error | 0 | 0 | 754 | 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)
n=int(input())
datasets=[input() for i in range(n)]
for line in datasets:
l = line.split("=",maxsplit=1)[0]
print(unfold_brackets(l)) |
s450391715 | p00109 | u919202930 | 1482233571 | Python | Python3 | py | Runtime Error | 0 | 0 | 753 | 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)
n=int(input())
datasets=[input() for i in range(n)]
for line in datasets:
l = line.split("=",maxsplit=1)[0]
print(unfold_brackets(l)) |
s046379636 | p00109 | u919202930 | 1482244457 | Python | Python3 | py | Runtime Error | 0 | 0 | 1105 | def calc(eqt): # assuming that eqt has no brackets.
l = eqt.split("+",maxsplit=1)
if len(l) == 2: # if eqt has "+", then
return (calc(l[0])+calc(l[1]))
l = eqt.split("-",maxsplit=1)
if len(l) == 2:# if eqt has "-", then
return (calc(l[0])-calc(l[1]))
l = eqt.split("*",maxsplit=1)
if len(l) == 2:# if eqt has "*", then
return (calc(l[0])*calc(l[1]))
l = eqt.split("/",maxsplit=1)
if len(l) == 2:# if eqt has "/", then
return (calc(l[0])/calc(l[1]))
return (int(eqt))
def unfold_brackets(eqt): # for example, eqt == "((3+5)*8+2)*2"
l = eqt.split(')',maxsplit=1)
if len(l) == 1: # if eqt has no brackets, then
return calc(eqt)
else:
# for example, l == ["((3+5", "*8+2)*2"]
ll = l[0].rsplit('(',maxsplit=1)
# ll == ["(","3+5"]
ll.append(l[1])
# ll == ["(","3+5","*8+2)*2"]
ll[1] = str(calc(ll[1]))
# ll == ["(",8,"*8+2)*2"]
l="".join(ll)
# ll == "(8*8+2)*2"
return unfold_brackets(l)
n=int(input())
datasets=[input() for i in range(n)]
for line in datasets:
l = line.split("=",maxsplit=1)[0]
print(unfold_brackets(l)) |
s307389784 | p00109 | u919202930 | 1482284226 | Python | Python3 | py | Runtime Error | 0 | 0 | 1107 | def calc(eqt): # assuming that eqt has no brackets.
l = eqt.split("+",maxsplit=1)
if len(l) == 2: # if eqt has "+", then
return (calc(l[0])+calc(l[1]))
l = eqt.split("-",maxsplit=1)
if len(l) == 2:# if eqt has "-", then
return (calc(l[0])-calc(l[1]))
l = eqt.split("*",maxsplit=1)
if len(l) == 2:# if eqt has "*", then
return (calc(l[0])*calc(l[1]))
l = eqt.split("/",maxsplit=1)
if len(l) == 2:# if eqt has "/", then
return (calc(l[0])/calc(l[1]))
return (int(eqt))
def unfold_brackets(eqt): # for example, eqt == "((3+5)*8+2)*2"
l = eqt.split(')',maxsplit=1)
if len(l) == 1: # if eqt has no brackets, then
return calc(eqt)
else:
# for example, l == ["((3+5", "*8+2)*2"]
ll = l[0].rsplit('(',maxsplit=1)
# ll == ["(","3+5"]
ll.append(l[1])
# ll == ["(","3+5","*8+2)*2"]
ll[1] = str(calc(ll[1]))
# ll == ["(",8,"*8+2)*2"]
l="".join(ll)
# ll == "(8*8+2)*2"
return unfold_brackets(l)
n=int(input())
datasets=[input() for i in range(0,n)]
for line in datasets:
l = line.split("=",maxsplit=1)[0]
print(unfold_brackets(l)) |
s037737420 | p00109 | u919202930 | 1482290224 | Python | Python3 | py | Runtime Error | 0 | 0 | 1176 | def calc(eqt): # assuming that eqt has no brackets.
l = eqt.split("+",maxsplit=1)
if len(l) == 2: # if eqt has "+", then
return (calc(l[0])+calc(l[1]))
l = eqt.split("-",maxsplit=1)
if len(l) == 2:# if eqt has "-", then
return (calc(l[0])-calc(l[1]))
l = eqt.split("*",maxsplit=1)
if len(l) == 2:# if eqt has "*", then
return (calc(l[0])*calc(l[1]))
l = eqt.split("/",maxsplit=1)
if len(l) == 2:# if eqt has "/", then
return (calc(l[0])//calc(l[1]))
return (int(eqt))
def unfold_brackets(eqt): # for example, eqt == "((3+5)*8+2)*2"
l = eqt.split(')',maxsplit=1)
if len(l) == 1: # if eqt has no brackets, then
return calc(eqt)
else:
# for example, l == ["((3+5", "*8+2)*2"]
ll = l[0].rsplit('(',maxsplit=1)
# ll == ["(","3+5"]
ll.append(l[1])
# ll == ["(","3+5","*8+2)*2"]
ll[1] = str(calc(ll[1]))
# ll == ["(",8,"*8+2)*2"]
l="".join(ll)
# ll == "(8*8+2)*2"
return unfold_brackets(l)
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(unfold_brackets(l))
except EOFError:
break |
s866235860 | p00109 | u371539389 | 1499681396 | Python | Python3 | py | Runtime Error | 0 | 0 | 1343 | #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 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(int(calc(s[:-1:])))
|
s555721813 | p00109 | u371539389 | 1499682627 | Python | Python3 | py | Runtime Error | 0 | 0 | 1248 | #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 calculator(s[:x[0]:])/calculator(s[x[0]+1::])
def calc(s):
while "(" in s:
closec=s.find(")")
openc=lastfind(s[:closec:],"(")
t=s[:openc:]+str(calculator(s[openc+1:closec:]))+s[closec+1::]
s=t
return calculator(s)
n=int(input())
for count in range(n):
s=input()
print(int(calc(s[:-1:])))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.