zadania 1

This commit is contained in:
Weranda 2023-10-26 20:28:12 +02:00
parent 0c23da0e15
commit 0534ee7527
4 changed files with 162 additions and 0 deletions

34
TaskA01/hamlet.py Normal file
View File

@ -0,0 +1,34 @@
import time
start = time.time()
path = "TaskA01\shakespeare.in"
file = open(path,"r",encoding="utf8")
count = 0
lines_count = 0
used = False
lines = []
all_lines = file.readlines()
for l in all_lines:
lines_count += 1
used = False
for char in l:
if char == "H" and count == 0:
count += 1
elif char == "a" and count == 1:
count += 1
elif char == "m" and count == 2:
count += 1
elif char == "l" and count == 3:
count += 1
elif char == "e" and count == 4:
count += 1
elif char == "t" and count == 5:
count = 0
if used == False:
lines.append(lines_count)
used = True
else:
count = 0
print(lines)
file.close()
end = time.time()
print(end - start)

41
TaskA02/pies.py Normal file
View File

@ -0,0 +1,41 @@
path = "TaskA02\polish_wiki_excerpt.in"
file = open(path,"r",encoding="utf8")
count = 0
lines_count = 0
used = False
lines = []
all_lines = file.readlines()
i = 0
for l in all_lines:
length = len(l.strip())
lines_count += 1
used = False
i = 0
for char in l:
i += 1
if i != 1:
if char == " " and count == 0:
count += 1
if (char == "p" or char == "P") and (count == 0 or count == 1):
count += 1
elif (char == "i" or char == "I") and (count == 1 or count == 2):
count += 1
elif (char == "e" or char == "E") and (count == 2 or count == 3):
count += 1
elif (char == "s" or char == "S") and (count == 3 or count == 4):
count += 1
if length == i:
count = 0
if used == False:
lines.append(lines_count)
used = True
elif (char == " ") and (count == 4 or count == 5):
count = 0
if used == False:
lines.append(lines_count)
used = True
else:
count = 0
print(lines)
file.close()

41
TaskA03/date.py Normal file
View File

@ -0,0 +1,41 @@
def is_number(char):
numbers = ['0','1','2','3','4','5','6','7','8','9']
for i in numbers:
if char == i:
return True
path = "TaskA03\polish_wiki_excerpt.in"
file = open(path,"r",encoding="utf8")
count = 0
lines_count = 0
used = False
lines = []
all_lines = file.readlines()
for l in all_lines:
lines_count += 1
used = False
for char in l:
if char == "1":
count += 1
elif char == "9" and count == 1:
count += 1
elif count == 2 and is_number(char) == True:
count += 1
elif count == 3 and is_number(char) == True:
count += 1
elif char == " " and count == 4:
count += 1
elif char == "r" and count == 5:
count += 1
elif char == "." and count == 6:
count = 0
if used == False:
lines.append(lines_count)
used = True
else:
count = 0
print(lines)
file.close()

46
TaskA04/digits.py Normal file
View File

@ -0,0 +1,46 @@
def is_number(char):
numbers = ['0','1','2','3','4','5','6','7','8','9']
for i in numbers:
if char == i:
return True
path = "TaskA04\polish_wiki_excerpt.exp"
file = open(path,"r",encoding="utf8")
count = 0
length = 0
digits = []
digit = ""
all_lines = file.readlines()
for l in all_lines:
line_length = len(l.strip())
used = False
space = False
count = 0
i = 0
for char in l:
i += 1
if i == 1:
space = True
if char == " " or line_length == (i-1):
space = True
if count != 0:
if length == 0:
length = count
digits.append(digit)
elif count > length:
length = count
digits.clear()
digits.append(digit)
elif count == length:
digits.append(digit)
digit = ""
count = 0
elif is_number(char) == True and space == True:
count += 1
digit += char
else:
count = 0
digit = ""
print(digits)
file.close()