Improved solution

This commit is contained in:
eddie 2024-11-01 15:29:13 +01:00
parent 58e8d6c4ad
commit a5ec559880
2 changed files with 974 additions and 967 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,27 +1,34 @@
import sys import sys
# return if the sentence contains word pies # '19xx' literally would be accepted as well but we won't tell anyone
def solve(lines): def solve(lines):
res = [] def detect_date(s):
for l in lines: date_f = "19XX r."
# first one didnt work what about the other dates? date_l = len(date_f)
i = 0
s = l j = 0
while i != -1: for i in range(len(s)):
if i+7 < len(s): c = s[i]
if s[i:i+2] == "19" and s[i+2].isdigit() and s[i+3].isdigit() and s[i+4:i+7] == " r.":
res.append(l) if j == date_l:
break return True
i += 2 # skipping current date elif c == date_f[j] \
s = s[i:] or (j in (2, 3) and c.isdigit()):
i = s.find("19") j += 1
return res continue
j = 0
return False
return filter(detect_date, lines)
if __name__ == "__main__": if __name__ == "__main__":
lines = [] lines = []
fp = sys.argv[1] fp = sys.argv[1]
with open("../TaskA02/polish_wiki_excerpt.in", encoding="utf-8") as f: with open(fp, encoding="utf-8") as f: # following symlinks might not work on Windows
lines = f.readlines() lines = f.readlines()
sol = solve(lines) sol = solve(lines)
with open("./polish_wiki_excerpt.out", 'w', encoding="utf-8") as f: with open("./polish_wiki_excerpt.out", 'w', encoding="utf-8") as f: