Add: 07->08
This commit is contained in:
37
2015/08.py
Normal file
37
2015/08.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import re
|
||||
|
||||
# Fill Input
|
||||
|
||||
try:
|
||||
with open("08.txt", 'r', encoding='utf-8') as file:
|
||||
input = file.read()
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
||||
# Result
|
||||
res1, res2 = 0, 0
|
||||
for line in input.split('\n'):
|
||||
#for line in ["\"\"", "\"abc\"", "\"aaa\\\"aaa\"", "\"\\x27\""]:
|
||||
#res2 = 0
|
||||
it = iter(line)
|
||||
while c:=next(it, None):
|
||||
match c:
|
||||
case '\"':
|
||||
res1+=1
|
||||
res2+= 1
|
||||
pass
|
||||
case '\\':
|
||||
res1+=1
|
||||
res2+=1
|
||||
match c:= next(it):
|
||||
case 'x':
|
||||
next(it)
|
||||
next(it)
|
||||
res1+=2
|
||||
case '\"':
|
||||
res2+=1
|
||||
case _:
|
||||
pass
|
||||
res2+=2
|
||||
print(res1, res2+len(line))
|
||||
print(res1, res2)
|
||||
Reference in New Issue
Block a user