forked from miczar1/djfz-24_25
Compare commits
No commits in common. "03b60ae694140f0a0e7b6c7eb8a4956420bb57d3" and "73efd9ab295e32ab829772f785af124290a9d659" have entirely different histories.
03b60ae694
...
73efd9ab29
@ -1,32 +0,0 @@
|
|||||||
def is_numeric(s):
|
|
||||||
for char in s:
|
|
||||||
if char < '0' or char > '9':
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def find_lines_with_date_from_file(filename):
|
|
||||||
result = []
|
|
||||||
|
|
||||||
with open(filename, 'r', encoding='utf-8') as file:
|
|
||||||
lines = file.readlines()
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
i = 0
|
|
||||||
while i < len(line):
|
|
||||||
if i + 3 < len(line):
|
|
||||||
year_candidate = line[i:i+4]
|
|
||||||
if is_numeric(year_candidate):
|
|
||||||
year = int(year_candidate)
|
|
||||||
if 1900 <= year <= 1999:
|
|
||||||
if i + 6 < len(line) and line[i+4] == ' ' and line[i+5:i+7] == 'r.':
|
|
||||||
result.append(line.strip())
|
|
||||||
break
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
filename = 'TaskA03/simple.in'
|
|
||||||
output = find_lines_with_date_from_file(filename)
|
|
||||||
|
|
||||||
for line in output:
|
|
||||||
print(line)
|
|
@ -2,10 +2,10 @@ def extract_numbers(line):
|
|||||||
numbers = []
|
numbers = []
|
||||||
current_number = ""
|
current_number = ""
|
||||||
|
|
||||||
|
# Przechodzimy przez każdy znak w linii
|
||||||
for char in line:
|
for char in line:
|
||||||
# Sprawdzamy, czy znak jest cyfrą (ASCII dla cyfr to 48-57)
|
if char.isdigit():
|
||||||
if '0' <= char <= '9':
|
current_number += char # Dodajemy cyfrę do obecnej liczby
|
||||||
current_number += char
|
|
||||||
else:
|
else:
|
||||||
if current_number: # Jeśli obecna liczba została zakończona
|
if current_number: # Jeśli obecna liczba została zakończona
|
||||||
numbers.append(current_number)
|
numbers.append(current_number)
|
||||||
@ -15,14 +15,7 @@ def extract_numbers(line):
|
|||||||
if current_number:
|
if current_number:
|
||||||
numbers.append(current_number)
|
numbers.append(current_number)
|
||||||
|
|
||||||
# Ręczna implementacja metody join
|
return " ".join(numbers) # Zwracamy liczby jako ciąg rozdzielony spacjami
|
||||||
result = ""
|
|
||||||
for i in range(len(numbers)):
|
|
||||||
result += numbers[i]
|
|
||||||
if i < len(numbers) - 1: # Dodajemy spację między liczbami
|
|
||||||
result += " "
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
# Przetwarzanie danych wejściowych z pliku
|
# Przetwarzanie danych wejściowych z pliku
|
||||||
|
Loading…
Reference in New Issue
Block a user