Complete TaskA04
This commit is contained in:
parent
a5ec559880
commit
e3b4150554
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,58 @@
|
||||
import sys
|
||||
|
||||
def solve(lines):
|
||||
# from 0 to n-6
|
||||
date_f = "19XX r."
|
||||
date_l = len(date_f)
|
||||
|
||||
res = []
|
||||
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)
|
||||
|
||||
# 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]
|
||||
|
||||
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__":
|
||||
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.write('\n') # it expects for file to end with newline :)
|
Loading…
Reference in New Issue
Block a user