From 5c6a7a086c2ef36b49e56ebca0adc50eff2224e8 Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:19:33 +0300 Subject: [PATCH 01/17] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 714ee32..afc6c6f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Вот сюда нужно будет в первой работе с гитом добавит свое ФИО -## ФИО +## Вераксо Марк Владимирович ## Работа с репозиторием From af4fac0d8feabccc6837b6c119c2cf2325bd2f5c Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:20:27 +0300 Subject: [PATCH 02/17] Update __init__.py --- python/src/__init__.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/python/src/__init__.py b/python/src/__init__.py index e69de29..9b59b4d 100644 --- a/python/src/__init__.py +++ b/python/src/__init__.py @@ -0,0 +1,42 @@ +class Cat: + def __init__ (self, name: str, age: int, breed: str): + self.__name = name + self.__age = age + self.__breed = breed + self.check_age(age) + + def check_age(self, age:int): + if age < 0 or age > 18: + print(f"Вы указали не верный возраст вашего питомца!") + else: + self.__age = age + + @property + def name(self): + return self.__name + + @name.setter + def name(self, n: str): + self.__name = n + + @property + def age(self): + return self.__age + @age.setter + def age(self, a: int): + self.check_age(a) + self.__age = a + + @property + def breed(self): + return self.__breed + + @breed.setter + def breed(self, b: str): + self.__breed = b + + def output(self): + print(f"Имя вашего питомца - {self.__name}") + print(f"Возраст вашего питомца - {self.__age}") + print(f"Порода вашего питомца - {self.__breed}") + From 3ec7f7ea66f8acd051e588cf8febbd9c3591f141 Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:22:34 +0300 Subject: [PATCH 03/17] Update main.py --- python/src/main.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/python/src/main.py b/python/src/main.py index e37a77c..cbdd461 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -1,7 +1,5 @@ -def summ(a: int, b: int) -> int: - return a + b - +import __init__ if __name__ == "__main__": - print("Hello world") - print(summ(3, 4)) + cat1 = __init__.Cat("Пушок", 5, "Русская голубая") + cat1.output() From dd4144cf4c68433c87efca2241a0908b3fa87b48 Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 20 Feb 2024 19:27:34 +0300 Subject: [PATCH 04/17] Create firsttask.py --- python/src/module2/firsttask.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 python/src/module2/firsttask.py diff --git a/python/src/module2/firsttask.py b/python/src/module2/firsttask.py new file mode 100644 index 0000000..abe2505 --- /dev/null +++ b/python/src/module2/firsttask.py @@ -0,0 +1,16 @@ +def bubbles(nums): + len_nums = len(nums) + s = 0 + for i in range(len_nums - 1): + for j in range(len_nums - i - 1): + if nums[j] > nums[j+1]: + nums[j], nums[j+1] = nums[j+1], nums[j] + s += 1 + print(*nums) + if s == 0: + print(0) + +N = int(input()) +nums = list(map(int, input().split())) +bubbles(nums) + From 05a116ae184779b6aa4b59f9f5abdfb85ab04d4c Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 20 Feb 2024 19:28:02 +0300 Subject: [PATCH 05/17] Create secondtask --- python/src/module2/secondtask | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 python/src/module2/secondtask diff --git a/python/src/module2/secondtask b/python/src/module2/secondtask new file mode 100644 index 0000000..419a6be --- /dev/null +++ b/python/src/module2/secondtask @@ -0,0 +1,26 @@ +nums = [] +n = int(input("Введите длину списка: ")) +def bubbles(nums): + n = len(nums) +#для i в промежутке n-1 с последнего до второго + for i in range(n - 1, 0, -1): + for j in range(i): + if nums[j][1] > nums[j + 1][1]: + nums[j], nums[j + 1] = nums[j + 1], nums[j] + return nums + + +while len(nums) < n: + act = input("Введите пары чисел: ") + numbers = act.split() + try: + num1 = int(numbers[0]) + num2 = int(numbers[1]) + nums.append((num1, num2)) + except: + print("Вы должны ввести ДВА числа!") + +answer = bubbles(nums) +for a in answer: + print(*a) + From 523cc670f1e63aafd9f346f73028a39b7f769f93 Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:33:08 +0300 Subject: [PATCH 06/17] Update firsttask.py --- python/src/module2/firsttask.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/src/module2/firsttask.py b/python/src/module2/firsttask.py index abe2505..d656fba 100644 --- a/python/src/module2/firsttask.py +++ b/python/src/module2/firsttask.py @@ -1,3 +1,6 @@ +N = int(input()) +nums = list(map(int, input().split())) + def bubbles(nums): len_nums = len(nums) s = 0 @@ -9,8 +12,6 @@ def bubbles(nums): print(*nums) if s == 0: print(0) - -N = int(input()) -nums = list(map(int, input().split())) + bubbles(nums) From cb66a7164051c8d50d1d9bfca344489abe2ccfdf Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:39:09 +0300 Subject: [PATCH 07/17] Update secondtask --- python/src/module2/secondtask | 41 ++++++++++++++++------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/python/src/module2/secondtask b/python/src/module2/secondtask index 419a6be..9a39c57 100644 --- a/python/src/module2/secondtask +++ b/python/src/module2/secondtask @@ -1,26 +1,23 @@ -nums = [] -n = int(input("Введите длину списка: ")) -def bubbles(nums): - n = len(nums) -#для i в промежутке n-1 с последнего до второго - for i in range(n - 1, 0, -1): - for j in range(i): - if nums[j][1] > nums[j + 1][1]: - nums[j], nums[j + 1] = nums[j + 1], nums[j] - return nums +def bubble(numbers): + n = len(numbers) + for i in range(n): + for j in range(0, n-i-1): + if numbers[j][1] < numbers[j+1][1]: + numbers[j], numbers[j+1] = numbers[j+1], numbers[j] + if numbers[j][1] == numbers[j+1][1]: + numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] + if numbers[j][0] > numbers[j+1][0]: + numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j] + return numbers -while len(nums) < n: - act = input("Введите пары чисел: ") - numbers = act.split() - try: - num1 = int(numbers[0]) - num2 = int(numbers[1]) - nums.append((num1, num2)) - except: - print("Вы должны ввести ДВА числа!") +n = int(input()) +nums = [] +for _ in range(n): + num1, num2 = map(int, input().split()) + nums.append((num1, num2)) -answer = bubbles(nums) -for a in answer: - print(*a) +sort = bubble(nums) +for nums in sort: + print(nums[0], nums[1]) From d1cfc9da27b22366aeb49596a447a7a7bae5bc23 Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:40:18 +0300 Subject: [PATCH 08/17] Create thirdtask.py --- python/src/module2/thirdtask.py | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 python/src/module2/thirdtask.py diff --git a/python/src/module2/thirdtask.py b/python/src/module2/thirdtask.py new file mode 100644 index 0000000..4d28f12 --- /dev/null +++ b/python/src/module2/thirdtask.py @@ -0,0 +1,34 @@ +nums = list(map(int, input("Введите числа: ").split())) +def merge_sort(nums): + n = len(nums) + if len(nums) == 1: + return nums + if len(nums) == 0: + return nums + left_half = merge_sort(nums[:len(nums) // 2]) + right_half = merge_sort(nums[len(nums) // 2:]) + i = j = k = 0 +#Создаем список zlist, который будет состоять из нулей и по длине равный nums + zlist = [0] * len(nums) + while i < len(left_half) and j < len(right_half): + if left_half[i] <= right_half[j]: + zlist[k] = left_half[i] + i += 1 + else: + zlist[k] = right_half[j] + j += 1 + k += 1 + while i < len(left_half): + zlist[k] = left_half[i] + i += 1 + k += 1 + while j < len(right_half): + zlist[k] = right_half[j] + j += 1 + k += 1 + for i in range(len(nums)): + nums[i] = zlist[i] + return nums + +merge_sort(nums) +print(nums) From 6de2f46f14327d95f547f003e8b475233325620c Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:13:06 +0300 Subject: [PATCH 09/17] Create fourthtask.py --- python/src/module2/fourthtask.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 python/src/module2/fourthtask.py diff --git a/python/src/module2/fourthtask.py b/python/src/module2/fourthtask.py new file mode 100644 index 0000000..ea90b2a --- /dev/null +++ b/python/src/module2/fourthtask.py @@ -0,0 +1,30 @@ +def merge_sort_inversion_count(arr): + if len(arr) <= 1: + return arr, 0 + mid = len(arr) // 2 + left, inv_left = merge_sort_inversion_count(arr[:mid]) + right, inv_right = merge_sort_inversion_count(arr[mid:]) + sorted_arr, inversions = merge(left, right) + return sorted_arr, inversions + inv_left + inv_right + +def merge(left, right): + result = [] + inv = 0 + i = j = 0 + while i < len(left) and j < len(right): + if left[i] <= right[j]: + result.append(left[i]) + i += 1 + else: + result.append(right[j]) + j += 1 + inv += len(left) - i + result += left[i:] + result += right[j:] + return result, inv + +if __name__ == "__main__": + N = int(input()) + nums = list(map(int, input().split())) + sorted_nums, inversions = merge_sort_inversion_count(nums) + print(inversions From a6795d763696398147348002aea1b4b8d73eded8 Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:13:27 +0300 Subject: [PATCH 10/17] Rename fourthtask.py to task4.py --- python/src/module2/{fourthtask.py => task4.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename python/src/module2/{fourthtask.py => task4.py} (100%) diff --git a/python/src/module2/fourthtask.py b/python/src/module2/task4.py similarity index 100% rename from python/src/module2/fourthtask.py rename to python/src/module2/task4.py From e42987ac51748d29031c46a3e27c518129894967 Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:13:56 +0300 Subject: [PATCH 11/17] Rename secondtask to task2.py --- python/src/module2/{secondtask => task2.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename python/src/module2/{secondtask => task2.py} (100%) diff --git a/python/src/module2/secondtask b/python/src/module2/task2.py similarity index 100% rename from python/src/module2/secondtask rename to python/src/module2/task2.py From 9e907ba10148679548d90abc5586d64a53ac8377 Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:14:08 +0300 Subject: [PATCH 12/17] Rename firsttask.py to task1.py --- python/src/module2/{firsttask.py => task1.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename python/src/module2/{firsttask.py => task1.py} (100%) diff --git a/python/src/module2/firsttask.py b/python/src/module2/task1.py similarity index 100% rename from python/src/module2/firsttask.py rename to python/src/module2/task1.py From cb2c3a48470a46dca44a46cd2694cb3bfbd1f6ea Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:14:20 +0300 Subject: [PATCH 13/17] Rename thirdtask.py to task3.py --- python/src/module2/{thirdtask.py => task3.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename python/src/module2/{thirdtask.py => task3.py} (100%) diff --git a/python/src/module2/thirdtask.py b/python/src/module2/task3.py similarity index 100% rename from python/src/module2/thirdtask.py rename to python/src/module2/task3.py From 76a5ea944357a2bc13eb412081680424c56eb47c Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:14:45 +0300 Subject: [PATCH 14/17] Create task5.py --- python/src/module2/task5.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 python/src/module2/task5.py diff --git a/python/src/module2/task5.py b/python/src/module2/task5.py new file mode 100644 index 0000000..93870a6 --- /dev/null +++ b/python/src/module2/task5.py @@ -0,0 +1,4 @@ +N = int(input()) +nums = list(map(int, input().split())) +array = set(nums) +print(len(array)) From 52bb78d5eb73d00abb4e0a31b77ba3facdadbacb Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:15:10 +0300 Subject: [PATCH 15/17] Update task3.py --- python/src/module2/task3.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/src/module2/task3.py b/python/src/module2/task3.py index 4d28f12..e2f7409 100644 --- a/python/src/module2/task3.py +++ b/python/src/module2/task3.py @@ -1,4 +1,4 @@ -nums = list(map(int, input("Введите числа: ").split())) +nums = list(map(int, input().split())) def merge_sort(nums): n = len(nums) if len(nums) == 1: @@ -8,7 +8,6 @@ def merge_sort(nums): left_half = merge_sort(nums[:len(nums) // 2]) right_half = merge_sort(nums[len(nums) // 2:]) i = j = k = 0 -#Создаем список zlist, который будет состоять из нулей и по длине равный nums zlist = [0] * len(nums) while i < len(left_half) and j < len(right_half): if left_half[i] <= right_half[j]: From 125351d69df4996d5c1c2cab2fc58d9c13e890ca Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:15:36 +0300 Subject: [PATCH 16/17] Create task6.py --- python/src/module2/task6.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 python/src/module2/task6.py diff --git a/python/src/module2/task6.py b/python/src/module2/task6.py new file mode 100644 index 0000000..26ceafb --- /dev/null +++ b/python/src/module2/task6.py @@ -0,0 +1,28 @@ +def purchase_automation(): + types = int(input()) + storage = list(map(int, input().split())) + total = int(input()) + orders = list(map(int, input().split())) + + orders_count = {} + for order in orders: + if order in orders_count: + orders_count[order] += 1 + else: + orders_count[order] = 1 + + search_result = [] + for item in range(types): + if item + 1 in orders_count: + if storage[item] < orders_count[item+1]: + search_result.append("yes") + else: + search_result.append("no") + else: + search_result.append("no") + + return search_result + +output = purchase_automation() +for line in output: + print(line) From f855709ab18931178fc37512eb4825720bce3c5c Mon Sep 17 00:00:00 2001 From: MarkVRKS <143934528+MarkVRKS@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:16:12 +0300 Subject: [PATCH 17/17] Create task7.py --- python/src/module2/task7.py | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 python/src/module2/task7.py diff --git a/python/src/module2/task7.py b/python/src/module2/task7.py new file mode 100644 index 0000000..d3d0c48 --- /dev/null +++ b/python/src/module2/task7.py @@ -0,0 +1,49 @@ +N = int(input()) +nums = [int(input()) for _ in range(N)] +def bucket_sort(nums, exp, buckets): + dlina = N + output = [0] * dlina + counter = [0] * 10 + + for i in range(dlina): + index_of_1_bucket = nums[i] // exp + counter[index_of_1_bucket % 10] += 1 + + for i in range(1, 10): + counter[i] += counter[i - 1] + + for i in range(dlina - 1, -1, -1): + index_of_2_bucket = nums[i] // exp + output[counter[index_of_2_bucket % 10] - 1] = nums[i] + counter[index_of_2_bucket % 10] -= 1 + + for i in range(dlina): + nums[i] = output[i] + + print("Bucket status:") + for i in range(10): + print(f"Bucket {i}: {', '.join(str(num) for num in buckets[i])}") + +def secondary_sort(nums): + max_num = max(nums) + exp = 1 + buckets = [[] for _ in range(10)] + + print("Initial array:") + print(", ".join(str(num) for num in nums)) + + while max_num // exp > 0: + for num in nums: + buckets[num // exp % 10].append(num) + + bucket_sort(nums, exp, buckets) + + for i in range(10): + buckets[i] = [] + + exp *= 10 + + print("Sorted array:") + print(", ".join(str(num) for num in nums)) + +secondary_sort(nums)