jfz-2023-s473555/TaskA04/run.py

45 lines
1.0 KiB
Python
Raw Normal View History

2023-10-21 02:06:55 +02:00
import numbers
import os
DIR = os.path.dirname(__file__)
DIGITS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
def join_path(filename: str) -> str:
return os.path.join(DIR, filename)
def in_set(letter, set) -> bool:
for i in set:
if i == letter:
return True
return False
with open(
join_path("polish_wiki_excerpt.in"), "r", newline="", encoding="utf8"
) as file:
text = file.readlines()
numbers = []
for ind, line in enumerate(text):
numbers_line = []
i = 0
while i < len(line):
number = []
if in_set(line[i], DIGITS):
number.append(line[i])
for j in range(i + 1, len(line)):
if line[j].isdigit():
number.append(line[j])
else:
i += len(number) - 1
break
numbers_line.append(int("".join(number)))
i += 1
if len(numbers_line) != 0:
print(*numbers_line, sep=" ")
numbers.append(numbers_line)
# print(len(phrase_array_slow))