2024-11-01 13:57:56 +01:00
|
|
|
import sys
|
|
|
|
|
|
|
|
def solve(lines):
|
2024-11-01 16:28:16 +01:00
|
|
|
# from 0 to n-6
|
|
|
|
date_f = "19XX r."
|
|
|
|
date_l = len(date_f)
|
|
|
|
|
2024-11-01 13:57:56 +01:00
|
|
|
res = []
|
2024-11-01 16:28:16 +01:00
|
|
|
for l in lines:
|
|
|
|
# acc = []
|
|
|
|
|
|
|
|
j = 0
|
|
|
|
for i in range(len(l)):
|
|
|
|
c = l[i]
|
|
|
|
|
|
|
|
if j == date_l:
|
|
|
|
# acc.append(l[i-j: i])
|
|
|
|
res.append(l)
|
|
|
|
break
|
|
|
|
elif c == date_f[j] \
|
|
|
|
or (j in (2, 3) and c.isdigit()):
|
|
|
|
j += 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
j = 0
|
|
|
|
|
|
|
|
# res.append(" ".join(acc))
|
|
|
|
# return "\n".join(res)
|
|
|
|
return "".join(res)
|
2024-11-01 13:57:56 +01:00
|
|
|
|
2024-11-01 16:28:16 +01:00
|
|
|
# detect numbers. separate numbers by spaces
|
|
|
|
def solve(lines):
|
|
|
|
res = []
|
|
|
|
|
|
|
|
j = 0
|
2024-11-01 13:57:56 +01:00
|
|
|
for l in lines:
|
|
|
|
numbers = []
|
2024-11-01 16:28:16 +01:00
|
|
|
for i in range(len(l)):
|
|
|
|
c = l[i]
|
|
|
|
|
|
|
|
if j > 0 and not c.isdigit():
|
|
|
|
numbers.append(l[i-j:i])
|
|
|
|
j = j+1 if (c.isdigit() and c.isascii()) else 0
|
2024-11-01 13:57:56 +01:00
|
|
|
|
2024-11-01 16:28:16 +01:00
|
|
|
if numbers:
|
|
|
|
res.append(' '.join(numbers))
|
|
|
|
return '\n'.join(res)
|
2024-11-01 13:57:56 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
lines = []
|
|
|
|
|
|
|
|
fp = sys.argv[1]
|
2024-11-01 16:28:16 +01:00
|
|
|
with open(fp, encoding="utf-8") as f:
|
2024-11-01 13:57:56 +01:00
|
|
|
lines = f.readlines()
|
|
|
|
sol = solve(lines)
|
|
|
|
with open("./polish_wiki_excerpt.out", 'w', encoding="utf-8") as f:
|
2024-11-01 16:28:16 +01:00
|
|
|
f.writelines(sol)
|
|
|
|
f.write('\n') # it expects for file to end with newline :)
|