diff --git a/TaskA01/hamlet.py b/TaskA01/hamlet.py new file mode 100644 index 0000000..7c31a71 --- /dev/null +++ b/TaskA01/hamlet.py @@ -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) \ No newline at end of file diff --git a/TaskA02/pies.py b/TaskA02/pies.py new file mode 100644 index 0000000..f4ad576 --- /dev/null +++ b/TaskA02/pies.py @@ -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() \ No newline at end of file diff --git a/TaskA03/date.py b/TaskA03/date.py new file mode 100644 index 0000000..355806d --- /dev/null +++ b/TaskA03/date.py @@ -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() + + \ No newline at end of file diff --git a/TaskA04/digits.py b/TaskA04/digits.py new file mode 100644 index 0000000..d71e58d --- /dev/null +++ b/TaskA04/digits.py @@ -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() \ No newline at end of file