djfz-24_25/TaskA03/solution.py

35 lines
860 B
Python
Raw Normal View History

2024-10-28 16:32:25 +01:00
import sys
2024-11-01 15:29:13 +01:00
# '19xx' literally would be accepted as well but we won't tell anyone
2024-10-28 16:32:25 +01:00
def solve(lines):
2024-11-01 15:29:13 +01:00
def detect_date(s):
date_f = "19XX r."
date_l = len(date_f)
j = 0
for i in range(len(s)):
c = s[i]
if j == date_l:
return True
elif c == date_f[j] \
or (j in (2, 3) and c.isdigit()):
j += 1
continue
j = 0
return False
return filter(detect_date, lines)
2024-10-28 16:32:25 +01:00
if __name__ == "__main__":
lines = []
fp = sys.argv[1]
2024-11-01 15:29:13 +01:00
with open(fp, encoding="utf-8") as f: # following symlinks might not work on Windows
2024-10-28 16:32:25 +01:00
lines = f.readlines()
sol = solve(lines)
with open("./polish_wiki_excerpt.out", 'w', encoding="utf-8") as f:
f.writelines(sol)