diff --git a/README.md b/README.md index 714ee32..1a409c9 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # Репозиторий для работ по курсу информатика -Вот сюда нужно будет в первой работе с гитом добавит свое ФИО - -## ФИО +## Козлов Егор Александрович, 1/278 ## Работа с репозиторием diff --git a/python/src/main.py b/python/src/main.py deleted file mode 100644 index e37a77c..0000000 --- a/python/src/main.py +++ /dev/null @@ -1,7 +0,0 @@ -def summ(a: int, b: int) -> int: - return a + b - - -if __name__ == "__main__": - print("Hello world") - print(summ(3, 4)) diff --git a/python/src/module1/document.py b/python/src/module1/document.py new file mode 100644 index 0000000..b36357b --- /dev/null +++ b/python/src/module1/document.py @@ -0,0 +1,80 @@ +# Kozlov Egor 1/278; Variant 11 + +class Document: + def __init__(self, path: str, docType: str, docSize: int): + if not isinstance(path, str): + raise TypeError("path must be str") + + if not isinstance(docType, str): + raise TypeError("docType must be str") + + self.__documentPath = path + self.__documentType = docType + self.documentSize = docSize + + @property + def documentPath(self) -> str: + return self.__documentPath + + @property + def documentType(self) -> str: + return self.__documentType + + @property + def documentSize(self) -> int: + return self.__documentSize + + @documentSize.setter + def documentSize(self, value) -> None: + if not isinstance(value, int): + raise TypeError("docSize must be int") + + if value < 0: + raise ValueError(value) + + self.__documentSize = value + + def __str__(self) -> str: + return f"Document: '{self.documentPath}', '{self.documentType}', {self.documentSize}" + + +if __name__ == "__main__": + print("Test 1") + instance = Document("/media/Files/Script.docx", "docx", 32000) + + print("Test 2") + try: + Document(32, "docx", 32000) # type: ignore + except Exception as e: + print("Catched:", e) + + print("Test 3") + try: + Document("/media/Files/Script.docx", 128, 32000) # type: ignore + except Exception as e: + print("Catched:", e) + + print("Test 4") + try: + Document("/media/Files/Script.docx", "docx", "32000") # type: ignore + except Exception as e: + print("Catched:", e) + + print("Test 5") + try: + Document("/media/Files/Script.docx", "docx", -10) + except Exception as e: + print("Catched:", e) + + print(str(instance)) + + instance.documentSize = 1600 + + print(str(instance)) + + try: + instance.documentSize = -18 + except Exception as e: + print("Catched:", e) + + print(str(instance)) diff --git a/python/src/module1/hello.py b/python/src/module1/hello.py deleted file mode 100644 index bdb9c05..0000000 --- a/python/src/module1/hello.py +++ /dev/null @@ -1,22 +0,0 @@ -""" ->>> import io, sys ->>> sys.stdin = io.StringIO(chr(10).join(['Vasya'])) ->>> hello() -Hello, Vasya! ->>> sys.stdin = io.StringIO(chr(10).join(['Petya'])) ->>> hello() -Hello, Petya! ->>> sys.stdin = io.StringIO(chr(10).join(['Olya'])) ->>> hello() -Hello, Olya! -""" - - -def hello(): - name = input() - print(f'Hello, {name}!') - - -if __name__ == "__main__": - import doctest - doctest.testmod(verbose=True) diff --git a/python/src/module1/summ.py b/python/src/module1/summ.py deleted file mode 100644 index cd5e905..0000000 --- a/python/src/module1/summ.py +++ /dev/null @@ -1,22 +0,0 @@ -""" ->>> import io, sys ->>> sys.stdin = io.StringIO(chr(10).join(['10 12'])) # input ->>> summ() -22 ->>> sys.stdin = io.StringIO(chr(10).join(['1 1'])) # input ->>> summ() -2 ->>> sys.stdin = io.StringIO(chr(10).join(['10000 10000'])) # input ->>> summ() -20000 -""" - - -def summ(): - a, b = map(int, input().split(' ')) - print(a + b) - - -if __name__ == "__main__": - import doctest - doctest.testmod(verbose=True) diff --git a/python/src/module2/bubble_sort.py b/python/src/module2/bubble_sort.py deleted file mode 100644 index ac28b7e..0000000 --- a/python/src/module2/bubble_sort.py +++ /dev/null @@ -1,36 +0,0 @@ -""" ->>> import io, sys ->>> sys.stdin = io.StringIO(chr(10).join(['4','4 3 2 1'])) ->>> bubble_sort() -3 4 2 1 -3 2 4 1 -3 2 1 4 -2 3 1 4 -2 1 3 4 -1 2 3 4 -""" - - -def bubble_sort(): - n = input() - inp_string = input() - str_lst = inp_string.split(" ") - res = [] - for item in str_lst: - res.append(int(item)) - - n = len(res) - num_swap = 0 - for i in range(0, n - 1): - for j in range(0, n - 1 - i): - if res[j] > res[j + 1]: - res[j], res[j + 1] = res[j + 1], res[j] - num_swap += 1 - print(" ".join(map(str, res))) - if num_swap == 0: - print("0") - - -if __name__ == "__main__": - import doctest - doctest.testmod(verbose=True) diff --git a/python/src/module2/task_1.py b/python/src/module2/task_1.py new file mode 100644 index 0000000..6949041 --- /dev/null +++ b/python/src/module2/task_1.py @@ -0,0 +1,20 @@ +totals = int(input()) +elements = list(map(int, input().split(" "))) + +no_swipes_were_made = True +for outer_index in range(len(elements) - 1, 0, -1): + list_is_sorted = True + for inner_index in range(outer_index): + if elements[inner_index] > elements[inner_index + 1]: + elements[inner_index], elements[inner_index + 1] = ( + elements[inner_index + 1], + elements[inner_index], + ) + list_is_sorted = False + no_swipes_were_made = False + print(*elements) + if list_is_sorted: + break + +if no_swipes_were_made: + print(0) diff --git a/python/src/module2/task_2.py b/python/src/module2/task_2.py new file mode 100644 index 0000000..7921cd4 --- /dev/null +++ b/python/src/module2/task_2.py @@ -0,0 +1,33 @@ +# Utils +def check_swipe_requirement( + record_current: list[int], record_to_swipe: list[int] +) -> bool: + price_current = record_current[1] + price_to_check = record_to_swipe[1] + + if price_current == price_to_check: + id_current = record_current[0] + id_to_check = record_to_swipe[0] + return id_to_check > id_current + else: + return price_to_check < price_current + + +# Program start +total_count = int(input()) +records = [None] * total_count # type: list[list[int] | None] + +# Read & sort 'at the run' +for outer_index in range(total_count): + record_to_insert = list(map(int, input().split(" "))) + inner_index = outer_index - 1 + while inner_index >= 0 and check_swipe_requirement( + record_to_insert, records[inner_index] # type: ignore + ): + records[inner_index + 1] = records[inner_index] + inner_index -= 1 + records[inner_index + 1] = record_to_insert + +# Output +for record in records: + print(record[0], record[1]) # type: ignore diff --git a/python/src/module2/task_3.py b/python/src/module2/task_3.py new file mode 100644 index 0000000..f072524 --- /dev/null +++ b/python/src/module2/task_3.py @@ -0,0 +1,44 @@ +# Utils +def merge(arr1, arr2): + result = [] + index1 = 0 + index2 = 0 + + while index1 < len(arr1) and index2 < len(arr2): + if arr1[index1] < arr2[index2]: + result.append(arr1[index1]) + index1 += 1 + else: + result.append(arr2[index2]) + index2 += 1 + + while index1 < len(arr1): + result.append(arr1[index1]) + index1 += 1 + + while index2 < len(arr2): + result.append(arr2[index2]) + index2 += 1 + + return result + + +def sort_with_print(arr, print_offset=1): + if len(arr) <= 1: + return arr + + split_index = len(arr) // 2 + + sorted1 = sort_with_print(arr[0:split_index], print_offset) + sorted2 = sort_with_print(arr[split_index:], print_offset + split_index) + merged = merge(sorted1, sorted2) + print(print_offset, print_offset + len(arr) - 1, merged[0], merged[-1]) + return merged + + +# Input +totals = int(input()) +list = list(int(i) for i in input().split(" ") if i.strip() != "") + +list = sort_with_print(list) +print(*list) diff --git a/python/src/module2/task_4.py b/python/src/module2/task_4.py new file mode 100644 index 0000000..86becbe --- /dev/null +++ b/python/src/module2/task_4.py @@ -0,0 +1,46 @@ +# Utils +def merge(arr1, arr2): + result = [] + index1 = 0 + index2 = 0 + total = 0 + + while index1 < len(arr1) and index2 < len(arr2): + if arr1[index1] <= arr2[index2]: + result.append(arr1[index1]) + index1 += 1 + else: + # if arr1[index1] != arr2[index2]: + total += len(arr1) - index1 + result.append(arr2[index2]) + index2 += 1 + # counts += 1 + + while index1 < len(arr1): + result.append(arr1[index1]) + index1 += 1 + + while index2 < len(arr2): + result.append(arr2[index2]) + index2 += 1 + return (result, total) + + +def sort_with_print(arr, print_offset=1): + if len(arr) <= 1: + return (arr, 0) + + split_index = len(arr) // 2 + + sorted1 = sort_with_print(arr[0:split_index], print_offset) + sorted2 = sort_with_print(arr[split_index:], print_offset + split_index) + merged = merge(sorted1[0], sorted2[0]) + return (merged[0], sorted1[1] + sorted2[1] + merged[1]) + + +# Input +totals = int(input()) +list = list(int(i) for i in input().split(" ") if i.strip() != "") + +list = sort_with_print(list) +print(list[1]) diff --git a/python/src/module2/task_5.py b/python/src/module2/task_5.py new file mode 100644 index 0000000..5dc092d --- /dev/null +++ b/python/src/module2/task_5.py @@ -0,0 +1,49 @@ +# Utils +def merge(arr1, arr2): + result = [] + index1 = 0 + index2 = 0 + + while index1 < len(arr1) and index2 < len(arr2): + if arr1[index1] < arr2[index2]: + result.append(arr1[index1]) + index1 += 1 + else: + result.append(arr2[index2]) + index2 += 1 + + while index1 < len(arr1): + result.append(arr1[index1]) + index1 += 1 + + while index2 < len(arr2): + result.append(arr2[index2]) + index2 += 1 + + return result + + +def merge_sort(arr, print_offset=1): + if len(arr) <= 1: + return arr + + split_index = len(arr) // 2 + + sorted1 = merge_sort(arr[0:split_index], print_offset) + sorted2 = merge_sort(arr[split_index:], print_offset + split_index) + merged = merge(sorted1, sorted2) + # print(print_offset, print_offset + len(arr) - 1, merged[0], merged[-1]) + return merged + + +# Input +totals = int(input()) +list = list(int(i) for i in input().split(" ") if i.strip() != "") + +list = merge_sort(list) +counter = 1 +for index in range(len(list) - 1): + if list[index] != list[index + 1]: + counter += 1 + +print(counter) diff --git a/python/src/module2/task_6.py b/python/src/module2/task_6.py new file mode 100644 index 0000000..8902f89 --- /dev/null +++ b/python/src/module2/task_6.py @@ -0,0 +1,30 @@ +# Utils +def read_words(): + return (int(i) for i in input().split(" ") if i.strip() != "") + + +def read_ints(): + return map(int, read_words()) + + +# Input +count_of_kinds = int(input()) +kinds_at_storage = list(read_ints()) + +count_of_user_orders = int(input()) +user_orders = read_ints() + +# Summarization +summarized_user_orders = [0] * count_of_kinds + +for _ in range(count_of_user_orders): + current_order = next(user_orders) - 1 # Index correction + summarized_user_orders[current_order] += 1 + +# Result calculation +for kind_index in range(count_of_kinds): + print( + "yes" + if kinds_at_storage[kind_index] < summarized_user_orders[kind_index] + else "no" + ) diff --git a/python/src/module2/task_7.py b/python/src/module2/task_7.py new file mode 100644 index 0000000..d0268d0 --- /dev/null +++ b/python/src/module2/task_7.py @@ -0,0 +1,47 @@ +# Utils +def read_words(): + return list(input().strip() for i in range(int(input()))) + + +items = read_words() + +# print initial +print("Initial array:") +print(*items, sep=", ") + +# sorting process +buckets = [[] for _ in range(10)] # type: list[list[str]] + +# We could take any of itmes to take rank count. +# Length of each item is same. +rank_count = len(items[0]) + +for rank_num in range(rank_count): + print("**********") + # bucket calculation + for item in items: + rank_value = item[rank_count - rank_num - 1] + rank_value = ord(rank_value) - ord("0") + buckets[rank_value].append(item) + + items = [] + # print & order recalulation + + print("Phase", str(rank_num + 1)) + + for index, bucket in enumerate(buckets): + print(f"Bucket {index}: ", end="") + if bucket: + print(*bucket, sep=", ") + else: + print("empty") + + for item in bucket: + items.append(item) + + buckets[index] = [] + +# print sorted +print("**********") +print("Sorted array:") +print(*items, sep=", ") diff --git a/python/tests/test_main.py b/python/tests/test_main.py deleted file mode 100644 index 0280a2e..0000000 --- a/python/tests/test_main.py +++ /dev/null @@ -1,37 +0,0 @@ -import unittest -from src import main - - -class SummTests(unittest.TestCase): - - def test_positive(self): - res = main.summ(2, 3) - self.assertEqual(5, res) - - def test_zero(self): - res = main.summ(0, 0) - self.assertEqual(0, res) - - def test_one_negative(self): - res = main.summ(-2, 3) - self.assertEqual(1, res) - - def test_both_negative(self): - res = main.summ(-2, -4) - self.assertEqual(-6, res) - - def test_one_negative_zero_res(self): - res = main.summ(-2, 2) - self.assertEqual(0, res) - - def test_one_negative_and_text(self): - try: - main.summ(-2, "2") - except: - self.assertTrue(True) - return - self.fail() - - -if __name__ == '__main__': - unittest.main()