This commit is contained in:
2021-12-20 22:41:29 +01:00
parent ce02b1c91b
commit e3c1f47592
6 changed files with 85 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ S = { ")": 3, "]": 57, "}": 1197, ">": 25137, }
L = sys.stdin.read().splitlines()
N = 0
for l in L:
Q = deque(["y"]*120)
Q = deque(["y"]*1)
for c in l:
p = Q.pop()
if c in D: # if closing char

View File

@@ -1,11 +1,11 @@
import sys
from collections import deque
D = { ">":"<", ")":"(", "]":"[","}":"{", }
S = { "(":1, "[":2, "{":3, "<":4, }
S = { "(":1, "[":2, "{":3, "<":4, }
L = sys.stdin.read().splitlines()
N = []
for l in L:
Q = deque(["y"]*120)
Q = deque(["y"]) # add buffer to pop
fail = False
for c in l:
p = Q.pop()
@@ -20,7 +20,7 @@ for l in L:
Q.append(p)
Q.append(c)
if not fail:
R = list(Q)[120:]
R = list(Q)[1:]
s = 0
for r in reversed(R):
s = s*5 + S[r]