Skip to content

Lab5 to py + module2 #57

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

Open
wants to merge 1 commit into
base: master
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
11 changes: 11 additions & 0 deletions python/src/module2/tusc1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
a = int(input())
da = [int(vr) for vr in input().split()]
const = 0
for l in range(a-1):
for i in range(a-1):
if da[i] > da[i+1]:
const +=1
da[i], da[i+1] = da[i+1], da[i]
print(' '.join(map(str, da)))
if const == 0:
print(0)
16 changes: 16 additions & 0 deletions python/src/module2/tusc2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
a = int(input())
l = 0
spisok = []

while l < a:
list = [int(n) for n in input().split()]
spisok.append(list)
l += 1

for r in range(a-1):
for i in range(a-1):
if spisok[i][1] < spisok[i+1][1] or (spisok[i][1] == spisok[i+1][1] and spisok[i][0] > spisok[i+1][0]):
spisok[i], spisok[i+1] = spisok[i+1], spisok[i]

for list in spisok:
print(' '.join(map(str, list)))
30 changes: 30 additions & 0 deletions python/src/module2/tusc3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def soed2sp(a, b, Ind):
const = []
i = j = 0
while i <len(a) and j < len(b):
if a[i] < b[j]:
const.append(a[i])
i+=1
else:
const.append(b[j])
j+=1
if i<len(a):
const += a[i:]
if j<len(b):
const += b[j:]
stind = Ind[0]
endind = Ind[1]
print(stind, endind, const[0], const[-1])
return const

def soedsort(s, start=1):
if len(s) <= 1:
return s, start
middle = len(s)//2
left, left_Ind = soedsort(s[:middle], start)
right, right_Ind = soedsort(s[middle:], start + middle)
return soed2sp(left, right, [start, start + len(s) - 1]), start

n = int(input())
result, _ = soedsort(list(map(int, input().split())))
print(' '.join(map(str, result)))
28 changes: 28 additions & 0 deletions python/src/module2/tusc4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def soed2sp(a, b):
c = []
i = j = 0
invconst = 0
while i < len(a) and j < len(b):
if a[i] <= b[j]:
c.append(a[i])
i += 1
else:
c.append(b[j])
j += 1
invconst += len(a) - i
c += a[i:]
c += b[j:]
return c, invconst

def soedsort(s):
if len(s) <= 1:
return s, 0
middle = len(s) // 2
left, Leftinv = soedsort(s[:middle])
right, rightinv = soedsort(s[middle:])
soedlist, inv = soed2sp(left, right)
return soedlist, Leftinv + rightinv + inv

n = int(input())
result, invconst = soedsort(list(map(int, input().split())))
print(invconst)
38 changes: 38 additions & 0 deletions python/src/module2/tusc5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
def soedsort(a):
if len(a) > 1:
mid = len(a) // 2
left = a[:mid]
right = a[mid:]
soedsort(left)
soedsort(right)
i = j = l = 0
while i < len(left) and j < len(right):
if left[i] < right[j]:
a[l] = left[i]
i += 1
else:
a[l] = right[j]
j += 1
l += 1
while i < len(left):
a[l] = left[i]
i += 1
l += 1
while j < len(right):
a[l] = right[j]
j += 1
l += 1

def sortbis(a):
if len(a) <= 1:
return a
else:
st = a[0]
men = [x for x in a[1:] if x <= st]
bol = [x for x in a[1:] if x > st]
return sortbis(men) + [st] + sortbis(bol)

n = int(input())
num = list(map(int, input().split()))
soedsort(num)
result = []
15 changes: 15 additions & 0 deletions python/src/module2/tusc6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
vid = int(input())
listtov = [int(n) for n in input().split()]
b = int(input())
list = [int(n) for n in input().split()]
sche = [0]*(vid+1)
for i in list:
sche[i]+=1
sche.pop(0)
stopsche = 0
while stopsche < vid:
if sche[stopsche] > listtov[stopsche]:
print("yes")
else:
print("no")
stopsche += 1
23 changes: 23 additions & 0 deletions python/src/module2/tusc7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def sortr(list):
cor = [[] for _ in range(10)]
mlen = max(len(x) for x in list)
print("Initial array:\n" + ", ".join(list))
for p in range(mlen):
print("**********")
print(f"Phase {p + 1}")
for i in range(10):
for l in list:
if len(l) > p:
if int(l[-p-1]) == i:
cor[i].append(l)
print(f"Bucket {i}: {', '.join(cor[i]) if cor[i] else 'empty'}")

list = [x for b in cor for x in b]
cor = [[] for _ in range(10)]

print("**********")
print("Sorted array:\n" + ", ".join(list))

n = int(input())
list = [input() for _ in range(n)]
sortr(list)
27 changes: 27 additions & 0 deletions python/tests/Lab5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Mouse():
name = None
age = None
color = None
gender = None

def __init__(self, name: str, age: int, color: str, gender: str):
self.Check(name, age, color, gender)
self.name = name
self.age = age
self.color = color
self.gender = gender

def Check(self, name: str, age: int, color: str, gender: str ):
if not name.isalpha():
raise TypeError("Ошибка, неверный тип данных для параметра name. Ожидается строка.")
elif age < 0 or age > 5:
raise ValueError("Ошибка, неверно указано значение возраста")
elif not color.isalpha():
raise TypeError("Ошибка, неверный тип данных для параметра color. Ожидается строка.")
elif not gender.isalpha():
raise TypeError("Ошибка, неверный тип данных для параметра gender. Ожидается строка.")
def get(self):
if self.age == None or self.gender == None or self.color == None or self.age == None:
print("Есть неуказанные значения в параметрах человека: None, попробуйте пересоздать Мыша!")
else:
print(f"Мышонок создан.\nИмя мыша: {self.name}\nВозраст: {self.age} лет\nПол: {self.gender} \nЦвет: {self.color} ")
Empty file removed python/tests/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions python/tests/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Lab5 as laba

Mouse = input("Введите имя мыша: ")
Age = int(input("Введите возраст мыша: "))
Gender = input("Введите пол мыша: ")
Color = input("Введите цвет мыша: ")

Mysh1 = laba.Mouse(Mouse, Age, Color, Gender)

Mysh1.get()
37 changes: 0 additions & 37 deletions python/tests/test_main.py

This file was deleted.