From 3f1e3de00e8e68ff966cf0a4a3a0d15cfd1119fb Mon Sep 17 00:00:00 2001 From: GoidGoidGoida Date: Tue, 27 Feb 2024 22:03:29 +0300 Subject: [PATCH 1/2] lab6 --- python/lab6/main.py | 14 ++++++++++++++ python/lab6/mouse.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 python/lab6/main.py create mode 100644 python/lab6/mouse.py diff --git a/python/lab6/main.py b/python/lab6/main.py new file mode 100644 index 0000000..9d8e4be --- /dev/null +++ b/python/lab6/main.py @@ -0,0 +1,14 @@ +import mouse + +if __name__ == "__main__": + m1 = mouse.Mouse(5, "Ъ", 5) + m2 = mouse.Mouse(3, "Golang", 30) + + print("The name of the first mouse is {0}".format(m1.name)) + print("the age of the first mouse {0}".format(m1.age)) + + print("The name of the second mouse is {0}".format(m2.name)) + print("the age of the second mouse {0}".format(m2.age)) + + m1.mouseSqwueaking() + m2.mouseSqwueaking() \ No newline at end of file diff --git a/python/lab6/mouse.py b/python/lab6/mouse.py new file mode 100644 index 0000000..e8d3895 --- /dev/null +++ b/python/lab6/mouse.py @@ -0,0 +1,32 @@ +class Mouse(): + __age = 0 + __name = "" + __size = 0 + + def __init__(self, age, name, size): + self.age = age + self.__size = size + self.__name = name + + def mouseSqwueaking(self): + print("mouse {0} beeping\n".format(self.__name)) + + def age(self) -> int: + return self.__age + + def age(self, age): + assert(age >= 0 and age <= 10), "invalid age" + self.__age = age + + def size(self) -> int: + return self.__size + + def size(self, size): + assert(size >= 6 and size <= 80), "invalid size" + self.__size = size + + def name(self) -> str: + return self.__name + + def name(self, name): + self.__name = name \ No newline at end of file From 9c5f1eb583ba67c2952eee84dc0a77d2816d76a0 Mon Sep 17 00:00:00 2001 From: GoidGoidGoida Date: Wed, 20 Mar 2024 18:33:50 +0300 Subject: [PATCH 2/2] move from master to created branch --- python/src/YandexContest/module1/m1t1.py | 6 ++++ python/src/YandexContest/module1/m1t2.py | 3 ++ python/src/YandexContest/module2/m2t1.py | 13 +++++++ python/src/YandexContest/module2/m2t2.py | 17 +++++++++ python/src/YandexContest/module2/m2t3.py | 33 +++++++++++++++++ python/src/YandexContest/module2/m2t4.py | 33 +++++++++++++++++ python/src/YandexContest/module2/m2t5.py | 6 ++++ python/src/YandexContest/module2/m2t6.py | 16 +++++++++ python/src/YandexContest/module2/m2t7.py | 46 ++++++++++++++++++++++++ python/{ => src}/lab6/main.py | 0 python/{ => src}/lab6/mouse.py | 0 python/src/module1/hello.py | 22 ------------ python/src/module1/summ.py | 22 ------------ python/src/module2/bubble_sort.py | 36 ------------------- 14 files changed, 173 insertions(+), 80 deletions(-) create mode 100644 python/src/YandexContest/module1/m1t1.py create mode 100644 python/src/YandexContest/module1/m1t2.py create mode 100644 python/src/YandexContest/module2/m2t1.py create mode 100644 python/src/YandexContest/module2/m2t2.py create mode 100644 python/src/YandexContest/module2/m2t3.py create mode 100644 python/src/YandexContest/module2/m2t4.py create mode 100644 python/src/YandexContest/module2/m2t5.py create mode 100644 python/src/YandexContest/module2/m2t6.py create mode 100644 python/src/YandexContest/module2/m2t7.py rename python/{ => src}/lab6/main.py (100%) rename python/{ => src}/lab6/mouse.py (100%) delete mode 100644 python/src/module1/hello.py delete mode 100644 python/src/module1/summ.py delete mode 100644 python/src/module2/bubble_sort.py diff --git a/python/src/YandexContest/module1/m1t1.py b/python/src/YandexContest/module1/m1t1.py new file mode 100644 index 0000000..5afe802 --- /dev/null +++ b/python/src/YandexContest/module1/m1t1.py @@ -0,0 +1,6 @@ +#A + B + +a, b = input().split() +a = int(a) +b = int(b) +print(a + b) diff --git a/python/src/YandexContest/module1/m1t2.py b/python/src/YandexContest/module1/m1t2.py new file mode 100644 index 0000000..dd982c7 --- /dev/null +++ b/python/src/YandexContest/module1/m1t2.py @@ -0,0 +1,3 @@ +#Helo Peter + +print("Hello, " + input() + "!") \ No newline at end of file diff --git a/python/src/YandexContest/module2/m2t1.py b/python/src/YandexContest/module2/m2t1.py new file mode 100644 index 0000000..52648f0 --- /dev/null +++ b/python/src/YandexContest/module2/m2t1.py @@ -0,0 +1,13 @@ +#Сортировка пузырьком + +n=int(input()) +count=0 +mas=list(map(int, (input().split()))) +for i in range(n-1): + for j in range(n-i-1): + if mas[j] > mas[j+1]: + mas[j], mas[j+1] = mas[j+1], mas[j] + count+=1 + print(" ".join(map(str, mas))) +if count==0: + print((0)) \ No newline at end of file diff --git a/python/src/YandexContest/module2/m2t2.py b/python/src/YandexContest/module2/m2t2.py new file mode 100644 index 0000000..73e72ef --- /dev/null +++ b/python/src/YandexContest/module2/m2t2.py @@ -0,0 +1,17 @@ +#Сортировка пар + +n = int(input()) +count = 0 +mas = [] + +while count < n: + objectlist = [int(num) for num in input().split()] + mas.append(objectlist) + count += 1 +for j in range(n-1): + for i in range(n-1): + if mas[i][1] < mas[i+1][1] or (mas[i][1] == mas[i+1][1] and mas[i][0] > mas[i+1][0]): + mas[i], mas[i+1] = mas[i+1], mas[i] + +for objectlist in mas: + print(' '.join(map(str, objectlist))) \ No newline at end of file diff --git a/python/src/YandexContest/module2/m2t3.py b/python/src/YandexContest/module2/m2t3.py new file mode 100644 index 0000000..9cac4ab --- /dev/null +++ b/python/src/YandexContest/module2/m2t3.py @@ -0,0 +1,33 @@ +#Сортировка слиянием с выводом границ + +a = int(input()) +s = input().split() +mas= [] +for i in range(a): + mas.append(int(s[i])) + +def mergeArr(first, second, start): + result = [] + curr1 = 0 + curr2 = 0 + for i in range(len(first) + len(second)): + if (curr2 == len(second) or (curr1 < len(first) and first[curr1] <= second[curr2])): + result.append(first[curr1]) + curr1 += 1 + else: + result.append(second[curr2]) + curr2 += 1 + print(str(start + 1) + " " + str(start + len(result)) + " " + str(result[0]) + " " + str(result[len(result) - 1])) + return result + +def mergeSort(input, start, end): + if (end - start == 1): + return [input[start]] + middle = int((start + end) // 2) + firstHalf = mergeSort(input, start, middle) + secondHalf = mergeSort(input, middle, end) + return mergeArr(firstHalf, secondHalf, start) + +mas = mergeSort(mas, 0, len(mas)) + +print(" ".join(map(str, mas))) \ No newline at end of file diff --git a/python/src/YandexContest/module2/m2t4.py b/python/src/YandexContest/module2/m2t4.py new file mode 100644 index 0000000..d0270e2 --- /dev/null +++ b/python/src/YandexContest/module2/m2t4.py @@ -0,0 +1,33 @@ +#Число инверсий + +def mergeSort(a): + if len(a) <= 1: + return a,0 + l = a[0:len(a) // 2] + r = a[len(a) // 2:len(a)] + l,invl = mergeSort(l) + r,invr = mergeSort(r) + merged,inv = merge(l,r) + inv += invl + invr + return merged, inv + +def merge(a, b): + i, j, k, count = 0, 0, 0, 0 + c = [0]*(len(a) + len(b)) + while (k < len(c)): + if (j == len(b) or (i < len(a) and a[i] <= b[j])): + c[k] = a[i] + i += 1 + else: + c[k] = b[j] + count += (len(a) - i) + j += 1 + k += 1 + return c,count + +a = 0 +mas = [] +def task(): + n = int(input()) + print(mergeSort(list(map(int, input().split())))[1]) +task() \ No newline at end of file diff --git a/python/src/YandexContest/module2/m2t5.py b/python/src/YandexContest/module2/m2t5.py new file mode 100644 index 0000000..9eb6483 --- /dev/null +++ b/python/src/YandexContest/module2/m2t5.py @@ -0,0 +1,6 @@ +#Количество различных + +num=int(input()) +mas=list(map(int, (input().split()))) +slovar = dict(zip(mas,mas)) +print(len(slovar)) \ No newline at end of file diff --git a/python/src/YandexContest/module2/m2t6.py b/python/src/YandexContest/module2/m2t6.py new file mode 100644 index 0000000..55f0255 --- /dev/null +++ b/python/src/YandexContest/module2/m2t6.py @@ -0,0 +1,16 @@ +#Склад + +num = int(input()) +mas = list(map(int, (input().split()))) +buyers = int(input()) +buy = list(map(int, (input().split()))) +sell = [0]*num +for i in range(num): + mas[i] = [mas[i], i+1] +for j in range(buyers): + sell[buy[j] - 1] += 1 +for n in mas: + if n[0] < sell[n[1] - 1]: + print("yes") + else: + print("no") \ No newline at end of file diff --git a/python/src/YandexContest/module2/m2t7.py b/python/src/YandexContest/module2/m2t7.py new file mode 100644 index 0000000..ab984e9 --- /dev/null +++ b/python/src/YandexContest/module2/m2t7.py @@ -0,0 +1,46 @@ +#Поразрядная сортировка + +stringCount = int(input()) +stringList = [] + +for i in range(stringCount): + stringList.append(input()) + +def radixSort(array, elementLength, abLength): + process = [] + for i in range(abLength): + process.append([]) + for i in range(elementLength - 1, -1, -1): + for j in range(len(array)): + process[int(array[j][i])].append(array[j]) + count = 0 + for j in range(len(process)): + for k in range(len(process[j])): + array[count] = process[j][k] + count += 1 + printPhase(process, elementLength - i) + clearProcess(process, abLength) + +def printPhase(array, phaseCount): + print("Phase " + str(phaseCount)) + for i in range(len(array)): + value = "" + if len(array[i]) == 0: + value = "empty" + else: + value = ", ".join(array[i]) + print("Bucket " + str(i) + ": " + value) + print("*" * 10) + +def clearProcess(process, abLength): + for i in range(abLength): + process[i] = [] + +print("Initial array:") +print(", ".join(stringList)) +print("*" * 10) + +radixSort(stringList, len(stringList[0]), 10) + +print("Sorted array:") +print(", ".join(stringList)) \ No newline at end of file diff --git a/python/lab6/main.py b/python/src/lab6/main.py similarity index 100% rename from python/lab6/main.py rename to python/src/lab6/main.py diff --git a/python/lab6/mouse.py b/python/src/lab6/mouse.py similarity index 100% rename from python/lab6/mouse.py rename to python/src/lab6/mouse.py 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)