Puzzle du 9 décembre 2017
This commit is contained in:
parent
4f68addba2
commit
401b3271a5
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
data = sys.stdin.readline()
|
||||
total, i, currentscore, garbagecount = 0, 0, 0, 0
|
||||
in_garbage = False
|
||||
scores = []
|
||||
|
||||
while i < len(data):
|
||||
if data[i] == "!":
|
||||
i += 1
|
||||
elif data[i] == "<" and not in_garbage:
|
||||
in_garbage = True
|
||||
elif in_garbage:
|
||||
if data[i] == ">":
|
||||
in_garbage = False
|
||||
else:
|
||||
garbagecount += 1
|
||||
elif data[i] == "{" and not in_garbage:
|
||||
currentscore += 1
|
||||
scores.append(currentscore)
|
||||
elif data[i] == "}" and not in_garbage:
|
||||
currentscore -= 1
|
||||
total += scores.pop()
|
||||
i += 1
|
||||
|
||||
print(total, garbagecount)
|
Loading…
Reference in New Issue