forked from miczar1/djfz-24_25
Compare commits
3 Commits
58e8d6c4ad
...
5f61213d21
Author | SHA1 | Date | |
---|---|---|---|
|
5f61213d21 | ||
|
e3b4150554 | ||
|
a5ec559880 |
@ -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:
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,30 @@
|
|||||||
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 w in l.split():
|
for i in range(len(l)):
|
||||||
number = ''.join(filter(lambda c: c.isdigit(), w))
|
c = l[i]
|
||||||
if number:
|
|
||||||
numbers.append(number)
|
|
||||||
if numbers:
|
|
||||||
res.append(' '.join(numbers) + '\n')
|
|
||||||
|
|
||||||
return res
|
if j > 0 and not c.isdigit():
|
||||||
|
numbers.append(l[i-j:i])
|
||||||
|
j = j+1 if (c.isdigit() and c.isascii()) else 0
|
||||||
|
|
||||||
|
if numbers:
|
||||||
|
res.append(' '.join(numbers))
|
||||||
|
return '\n'.join(res)
|
||||||
|
|
||||||
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:
|
||||||
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 :)
|
Loading…
Reference in New Issue
Block a user