Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YandexContest m1 + m2 #62

Open
wants to merge 2 commits into
base: Gorjunov_Aleksandr_Alekseevich
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/src/YandexContest/module1/m1t1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#A + B

a, b = input().split()
a = int(a)
b = int(b)
print(a + b)
3 changes: 3 additions & 0 deletions python/src/YandexContest/module1/m1t2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Helo Peter

print("Hello, " + input() + "!")
13 changes: 13 additions & 0 deletions python/src/YandexContest/module2/m2t1.py
Original file line number Diff line number Diff line change
@@ -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))
17 changes: 17 additions & 0 deletions python/src/YandexContest/module2/m2t2.py
Original file line number Diff line number Diff line change
@@ -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)))
33 changes: 33 additions & 0 deletions python/src/YandexContest/module2/m2t3.py
Original file line number Diff line number Diff line change
@@ -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)))
33 changes: 33 additions & 0 deletions python/src/YandexContest/module2/m2t4.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions python/src/YandexContest/module2/m2t5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Количество различных

num=int(input())
mas=list(map(int, (input().split())))
slovar = dict(zip(mas,mas))
print(len(slovar))
16 changes: 16 additions & 0 deletions python/src/YandexContest/module2/m2t6.py
Original file line number Diff line number Diff line change
@@ -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")
46 changes: 46 additions & 0 deletions python/src/YandexContest/module2/m2t7.py
Original file line number Diff line number Diff line change
@@ -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))
14 changes: 14 additions & 0 deletions python/src/lab6/main.py
Original file line number Diff line number Diff line change
@@ -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()
32 changes: 32 additions & 0 deletions python/src/lab6/mouse.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 0 additions & 22 deletions python/src/module1/hello.py

This file was deleted.

22 changes: 0 additions & 22 deletions python/src/module1/summ.py

This file was deleted.

36 changes: 0 additions & 36 deletions python/src/module2/bubble_sort.py

This file was deleted.