Compare commits

..

No commits in common. "5f61213d21ab02b8540ab5850d4f72150b21dbce" and "58e8d6c4adeff94ff27a7eba5759f7995a3b04c4" have entirely different histories.

4 changed files with 20916 additions and 20927 deletions

View File

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

File diff suppressed because it is too large Load Diff

View File

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