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

Maksim Silin #28

Open
wants to merge 14 commits into
base: Maksim_Silin
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: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@

```shell
pip install pipenv
```

```
pipenv shell
```

После установки pipenv в левом нижнем углу при использовании `vscode` следует выбрать версию интерпретатора, привязанную к проекту
Maksim Silin
15 changes: 15 additions & 0 deletions src/bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
N=int(input(" "))
a= [int(i)for i in input().split(" ")]
num_swap=0
for i in range(N-1):
for j in range(N-1-i):
if a[j+1]<a[j]:
t = a[j+1]
a[j+1] = a[j]
a[j] = t
num_swap= num_swap+1
for i in range(N):
print(a[i],end=" ")
print()
if num_swap==0:
print(0)
17 changes: 17 additions & 0 deletions src/bubble_sort2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
n= int(input())
s=[]
for i in range (n):
s.append(input().split(" "))
s=[[int(s[i][j]) for j in range(2)] for i in range(n)]
for i in range(n-1):
for j in range (n-1-i):
if s[j][1]<s[j+1][1]:
t = s[j+1]
s[j+1] = s[j]
s[j] = t
if s[j][1]==s[j+1][1] and s[j][0]>s[j+1][0]:
t = s[j+1]
s[j+1] = s[j]
s[j] = t

[print(i[0], i[1]) for i in s]
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print("Hello world")
print("Maksim Silin")
2 changes: 2 additions & 0 deletions src/mod1_task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A,B = [int(i) for i in input().split(" ")]
print(A+B)
1 change: 1 addition & 0 deletions src/mod1_task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, "+input()+'!')
15 changes: 15 additions & 0 deletions src/mod2_task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
N=int(input(" "))
a= [int(i)for i in input().split(" ")]
num_swap=0
for i in range(N-1):
for j in range(N-1-i):
if a[j+1]<a[j]:
t = a[j+1]
a[j+1] = a[j]
a[j] = t
num_swap= num_swap+1
for i in range(N):
print(a[i],end=" ")
print()
if num_swap==0:
print(0)
17 changes: 17 additions & 0 deletions src/mod2_task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
n= int(input())
s=[]
for i in range (n):
s.append(input().split(" "))
s=[[int(s[i][j]) for j in range(2)] for i in range(n)]
for i in range(n-1):
for j in range (n-1-i):
if s[j][1]<s[j+1][1]:
t = s[j+1]
s[j+1] = s[j]
s[j] = t
if s[j][1]==s[j+1][1] and s[j][0]>s[j+1][0]:
t = s[j+1]
s[j+1] = s[j]
s[j] = t

[print(i[0], i[1]) for i in s]
35 changes: 35 additions & 0 deletions src/mod2_task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
def merge_sort(num, start,end):
if (end - start > 1):
mid = (start + end) // 2
merge_sort(num, start, mid)
merge_sort(num, mid, end)
left = num [start: mid]
right = num[mid: end]
internal_sort(num, left, right, start)
print(start +1, end, num[start], num[end - 1])
def internal_sort(mass, left, right, start):
i = j = 0 # i -> right j -> left
k = start
while i < len(right) and j < len(left):
if left[j] > right[i]:
mass[k] = right[i]
i = i+1
else:
mass[k] = left[j]
j =j+1
k =k+1
while j < len(left):
mass [k] = left[j]
j=j+1
k=k+1
while i < len(right):
mass[k] = right[i]
i=i+1
k=k+1
def main():
n = int(input())
num = list(map(int, input().split(maxsplit = n)))
merge_sort(num, 0, len(num))
print(*num)

main()
8 changes: 8 additions & 0 deletions src/mod2_task5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
c = 1
n = int(input())
numbers = list(map(int, input().split(maxsplit = n)))
numbers.sort()
for i in range(1, n):
if numbers[i-1] != numbers[i]:
c= c+1
print(c)
14 changes: 14 additions & 0 deletions src/mod2_task6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Q = int(input())
H = list(map(int, input().split(" ")))
s = int(input())
X = list(map(int, input().split(" ")))
def m(a, b, n):
mass = [0]*(n+1)
for j in b:
mass[j] = mass[j]+1
for i in range(n):
if a[i] >= mass[i+1]:
print("no")
else:
print("yes")
m(H, X, Q)
26 changes: 26 additions & 0 deletions src/mod2_task7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def taskseven(C, x):
digit = len(C[0])
for i in range(digit):
mass = [[] for j in range(10)]
for item in C:
index = int(item)//10**i % 10
mass[index].append(item)
print("Phase", i+1)
C = []
for i in range(10):
print("Bucket ", i ,":", sep = "", end=" ")
print(", ".join(mass[i]) if len(mass[i])>0 else "empty")
C += mass[i]
print("**********")
return C

x = int(input())
C = []
for i in range(x):
C.append(input())
print("Initial array:")
print(", ".join(C))
print("**********")
C = taskseven(C, x)
print("Sorted array:")
print(", ".join(C))
22 changes: 22 additions & 0 deletions src/mod3_task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def func(c):
mass=[0]*len(c)
m = a =0
for i in range(1, len(c)):
if i <= a:
mass[i] = min(mass[i-m], a-i+1)
while mass[i] + i < len(c) and c[mass[i]] == c[mass[i]+i]:
mass[i]= mass[i]+1
if mass [i] + i - 1 > a:
m=i
a = mass[i] + i - 1
return mass

def main():
c = input()
t = input()
s = func(t+"#" + c)
for i in range(len(s)):
if len(t) == s[i]:
print(i- len(t) - 1, end = " ")

main()
36 changes: 36 additions & 0 deletions src/mod3_task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def cyclic_shift(a,b,c):
hash = 0
for i in range(len(a)):
hash = (hash*b+ord(a[i]))%c
return hash

def function(a,t,b,c):
if a!=t:
mass = 1
t = t[1:] + t[0]
c_s = cyclic_shift(a,b,c)
t_s = cyclic_shift(t,b,c)
k = 1
for i in range(len(a)-1):
k=(k*b)%c
for i in range(len(t)-1):
if c_s == t_s:
break
else:
t_s = (b*(t_s-ord(t[i])*k) + ord(t[i]))%c
mass= mass+1
if c_s == t_s:
print(mass)
else:
print(-1)
else:
print(0)

def main():
a = input()
t = input()
b = 30
c = 1e9+6
a = function(a,t,b,c)

main()
23 changes: 23 additions & 0 deletions src/mod3_task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def period(c):
a = [0] * len(c)
for i in range(1, len(c)):
z = a[i-1]
while (z > 0 and c[z] != c[i]):
z = a[z - 1]
if c[i] == c[z]:
z= z+1
a[i] = z
return a

def main():
c = input()
c_t = c + '&' + c
L = period(c_t)
lr = L[-1]-L[len(c)-1]
z = len(c)//lr
if c[:lr]*z == c:
print(z)
else:
print(1)

main()
18 changes: 18 additions & 0 deletions src/mod3_task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def function(c):
x = len(c)
count = [0] * x
count[0] = 0
for i in range (x - 1):
j = count[i]
while (j > 0) and (c[i + 1] != c[j]):
j = count[j - 1]
if (c[i + 1] == c[j]):
count[i+1] = j + 1
else:
count[i + 1] = 0
return count
txt = str(input())
c = list(txt)
x = len(c)
pref = function(c)
print(x - pref[-1])
14 changes: 14 additions & 0 deletions src/mod4_task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def psp(c):
Counter = 0
mass = []
for i in c:
if (i == '('):
mass.append(i)
elif (mass != []) and (mass[-1] == '('):
mass.pop()
else:
Counter= Counter+1
return Counter+len(mass)

c = str(input())
print(psp(c))
23 changes: 23 additions & 0 deletions src/mod4_task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
p = int(input())
c = list(map(int, input().split()))

impasse = [0]
wayB = [0]

for i in range(p):
while impasse[-1] == wayB[-1] + 1:
wayB.append(impasse[-1])
impasse.pop()
if c[i] == wayB[-1] + 1:
wayB.append(c[i])
else:
impasse.append(c[i])

while impasse[-1] == wayB[-1] + 1:
wayB.append(impasse[-1])
impasse.pop()

if wayB[-1] == p:
print('YES')
else:
print('NO')
23 changes: 23 additions & 0 deletions src/mod4_task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def close(C, p):
stk = [p-1]
index = [0]*p
index[p-1] = -1
for i in range(p-2, -1, -1):
if C[stk[-1]] >= C[i]:
while (stk != []) and (C[stk[-1]] >= C[i]):
stk.pop()
if (stk == []):
index[i] = -1
else:
index[i] = stk[-1]
stk.append(i)
else:
index[i] = stk[-1]
stk.append(i)
return index


N = int(input())
C = list(map(int, input().split()))
C = close(C, N)
print(' '.join(map(str, C)))
17 changes: 17 additions & 0 deletions src/mod4_task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def min_segment(p, m_w, c):
mass = []
for i in range(m_w):
while mass and c[i] <= c[mass[-1]]:
mass.pop()
mass.append(i)
for i in range(m_w, p):
print(c[mass[0]])
while mass and i - m_w >= mass[0]:
mass.pop(0)
while mass and c[i] <= c[mass[-1]]:
mass.pop()
mass.append(i)
print(c[mass[0]])
N, K = map(int, input().split())
c = list(map(int, input().split()))
min_segment(N, K, c)