1
0
Fork 0

Puzzle du 9 décembre 2017

This commit is contained in:
Lucidiot 2017-12-09 12:05:32 +01:00
parent 4f68addba2
commit 401b3271a5
No known key found for this signature in database
GPG Key ID: 63BD9482C29D0F64
1 changed files with 26 additions and 0 deletions

26
2017/9/stream.py Normal file
View File

@ -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)