Compare commits

...

5 Commits

Author SHA1 Message Date
jwieczor
03b60ae694 3th task 2024-11-17 23:04:47 +01:00
jwieczor
80e1af2c88 4th task 2024-11-17 22:56:41 +01:00
jwieczor
73efd9ab29 4th task draft 2024-11-15 23:08:20 +01:00
jwieczor
df42c3965d second task draft 2024-11-15 22:55:53 +01:00
jwieczor
b213667c17 first task draft 2024-11-15 22:52:11 +01:00
4 changed files with 96 additions and 0 deletions

14
TaskA01/task01.py Normal file
View File

@ -0,0 +1,14 @@
def contains_word_hamlet(line):
target = "Hamlet"
line_length = len(line)
target_length = len(target)
for i in range(line_length - target_length + 1):
if line[i:i + target_length] == target:
return True
return False
with open('/Users/jwieczor/Desktop/djfz-24_25-jezyki-1/TaskA01/simple.in', 'r') as file:
for line in file:
if contains_word_hamlet(line):
print(line, end='')

15
TaskA02/task02.py Normal file
View File

@ -0,0 +1,15 @@
def contains_word_hamlet(line):
target = "pies"
line_lower = line.lower()
line_length = len(line_lower)
target_length = len(target)
for i in range(line_length - target_length + 1):
if line_lower[i:i + target_length] == target:
return True
return False
with open('/Users/jwieczor/Desktop/djfz-24_25-jezyki-1/TaskA02/simple.in', 'r') as file:
for line in file:
if contains_word_hamlet(line):
print(line, end='')

32
TaskA03/task03.py Normal file
View File

@ -0,0 +1,32 @@
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)

35
TaskA04/task04.py Normal file
View File

@ -0,0 +1,35 @@
def extract_numbers(line):
numbers = []
current_number = ""
for char in line:
# Sprawdzamy, czy znak jest cyfrą (ASCII dla cyfr to 48-57)
if '0' <= char <= '9':
current_number += char
else:
if current_number: # Jeśli obecna liczba została zakończona
numbers.append(current_number)
current_number = "" # Resetujemy licznik
# Dodajemy ostatnią liczbę, jeśli linia kończy się na cyfry
if current_number:
numbers.append(current_number)
# Ręczna implementacja metody join
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
input_file = '/Users/jwieczor/Desktop/djfz-24_25-jezyki-1/TaskA04/simple.in'
with open(input_file, 'r') as file:
for line in file:
result = extract_numbers(line.strip()) # Usuwamy końcowe białe znaki
if result: # Wypisujemy tylko linie, które mają liczby
print(result)