Compare commits

..

3 Commits

Author SHA1 Message Date
eddie
5f61213d21 Final polish 2024-11-01 16:29:07 +01:00
eddie
e3b4150554 Complete TaskA04 2024-11-01 16:28:16 +01:00
eddie
a5ec559880 Improved solution 2024-11-01 15:29:13 +01:00
4 changed files with 20927 additions and 20916 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,27 +1,34 @@
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):
res = []
for l in lines:
# first one didnt work what about the other dates?
i = 0
s = l
while i != -1:
if i+7 < len(s):
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)
break
i += 2 # skipping current date
s = s[i:]
i = s.find("19")
return res
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)
if __name__ == "__main__":
lines = []
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()
sol = solve(lines)
with open("./polish_wiki_excerpt.out", 'w', encoding="utf-8") as f:

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,30 @@
import sys
# detect numbers. separate numbers by spaces
def solve(lines):
res = []
j = 0
for l in lines:
numbers = []
for w in l.split():
number = ''.join(filter(lambda c: c.isdigit(), w))
if number:
numbers.append(number)
if numbers:
res.append(' '.join(numbers) + '\n')
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
return res
if numbers:
res.append(' '.join(numbers))
return '\n'.join(res)
if __name__ == "__main__":
lines = []
fp = sys.argv[1]
with open("../TaskA02/polish_wiki_excerpt.in", encoding="utf-8") as f:
with open(fp, encoding="utf-8") as f:
lines = f.readlines()
sol = solve(lines)
with open("./polish_wiki_excerpt.out", 'w', encoding="utf-8") as f:
f.writelines(sol)
f.writelines(sol)
f.write('\n') # it expects for file to end with newline :)