-
Notifications
You must be signed in to change notification settings - Fork 22
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
Lapshin alexander #137
Open
lapshal
wants to merge
5
commits into
Nastasia8:Lapshin_Alexander
Choose a base branch
from
lapshal:Lapshin_Alexander
base: Lapshin_Alexander
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Lapshin alexander #137
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
a=int(input()) | ||
s=input().split()[:a] | ||
k=[int(x) for x in s] | ||
m=0 | ||
for i in range(a-1): | ||
for j in range(a-1-i): | ||
if k[j+1]<k[j]: | ||
m=1 | ||
k[j],k[j+1]=k[j+1],k[j] | ||
print(*k,sep=" ") | ||
if m==0: | ||
print(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
a=int(input()) | ||
|
||
m=[] | ||
for i in range(a): | ||
k, v=map(int, input().split()) | ||
m.append([k,v]) | ||
m.sort(key=lambda x: x[0]) | ||
m.sort(key=lambda x: x[1], reverse = True) | ||
[print(i[0], i[1]) for i in m] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
def merge_sort(nums, start, end): | ||
if len(nums) > 1: | ||
middle = len(nums) // 2 | ||
left = nums[:middle] | ||
right = nums[middle:] | ||
merge_sort(left, start, start + middle - 1) | ||
merge_sort(right, start + middle, end) | ||
|
||
i = j = k = 0 | ||
while i < len(left) and j < len(right): | ||
if left[i] < right[j]: | ||
nums[k] = left[i] | ||
i+=1 | ||
else: | ||
nums[k] = right[j] | ||
j+=1 | ||
k+=1 | ||
|
||
while i < len(left): | ||
nums[k] = left[i] | ||
i+=1 | ||
k+=1 | ||
|
||
while j < len(right): | ||
nums[k] = right[j] | ||
j+=1 | ||
k+=1 | ||
|
||
print(start, end, nums[0], nums[-1]) | ||
|
||
N=int(input()) | ||
|
||
p = input().split()[:N] | ||
p = [int(x) for x in p] | ||
|
||
merge_sort(p, 1, len(p)) | ||
|
||
print(*p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
def merge_sort(arr): | ||
global count | ||
if len(arr) > 1: | ||
middle = len(arr) // 2 | ||
half1 = arr[:middle] | ||
half2 = arr[middle:] | ||
merge_sort(half1) | ||
merge_sort(half2) | ||
i = j = k = 0 | ||
while i < len(half1) and j < len(half2): | ||
if half1[i] > half2[j]: | ||
arr[k] = half2[j] | ||
j += 1 | ||
count += len(half1) - i | ||
else: | ||
arr[k] = half1[i] | ||
i += 1 | ||
k += 1 | ||
|
||
while i < len(half1): | ||
arr[k] = half1[i] | ||
k += 1 | ||
i += 1 | ||
|
||
while j < len(half2): | ||
arr[k] = half2[j] | ||
k += 1 | ||
j += 1 | ||
return arr | ||
|
||
n = int(input()) | ||
arr = list(map(int, input().split()))[:n] | ||
count = 0 | ||
merge_sort(arr) | ||
print(count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
a=int(input()) | ||
print(len(set(input().split()[:a]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
a= int(input()) | ||
c = input().split()[:a] | ||
c = [int(x) for x in c] | ||
b = int(input()) | ||
n= input().split()[:b] | ||
n = [int(x) for x in n] | ||
|
||
for i in range(0,a): | ||
if c[i] < n.count(i + 1): | ||
print('yes') | ||
else: | ||
print('no') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
n = int(input()) | ||
nums = [] | ||
inteng = 10 | ||
for i in range(n): | ||
nums.append(input()) | ||
print('Initial array:') | ||
print(', '.join(nums)) | ||
for i in range(len(str(max(nums)))): | ||
print('**********') | ||
print('Phase', i+1) | ||
buck = [[] for k in range(inteng)] | ||
for k in nums: | ||
f = int(k) // 10**i % 10 | ||
buck[f].append(k) | ||
nums = [] | ||
for k in range(inteng): | ||
nums = nums+buck[k] | ||
print('Bucket', k, end=": ") | ||
if len(buck[k]) == 0: | ||
print('empty') | ||
else: | ||
print(', '.join(map(str, buck[k]))) | ||
print('**********') | ||
print('Sorted array:') | ||
print(', '.join(map(str, nums))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def pref(s): | ||
p=[0]*len(s) | ||
for i in range(len(s)-1): | ||
k=p[i] | ||
while k>0 and s[i+1] != s[k]: | ||
k = p[k-1] | ||
if s[i+1] == s[k]: | ||
p[i+1] = k+1 | ||
else: | ||
p[i+1] = 0 | ||
return p | ||
|
||
S=input() | ||
T=input() | ||
a=T+"$"+S | ||
p=pref(a) | ||
for i in range(len(p)): | ||
if p[i] == len(T): | ||
print(i-2*len(T), end=" ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
def hash(s, x, p): | ||
hash_s = 0 | ||
for i in range(len(s)): | ||
hash_s = (hash_s * x + ord(s[i])) % p | ||
return hash_s | ||
|
||
def rolling_hash(s, t ,x ,p): | ||
if s != t: | ||
m = 1 | ||
t = t[1:] + t[0] | ||
hash_s = hash(s, x ,p) | ||
hash_t = hash(t, x ,p) | ||
x_t = 1 | ||
for i in range(len(s) - 1): | ||
x_t = (x_t * x) % p | ||
for i in range(len(t) - 1): | ||
if hash_s == hash_t: | ||
break | ||
else: | ||
hash_t = (x * (hash_t - ord(t[i]) * x_t) + ord(t[i])) % p | ||
m += 1 | ||
[print(m) if hash_s == hash_t else print(-1)] | ||
else: | ||
print(0) | ||
|
||
def main(): | ||
S = input() | ||
T = input() | ||
x = 26 | ||
p = 1e9 + 7 | ||
rolling_hash(S, T, x, p) | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
def fun(s): | ||
p = [0]*len(s) | ||
for i in range(len(s)-1): | ||
j = p[i] | ||
while j > 0 and s[j] != s[i+1]: | ||
j = p[j-1] | ||
if s[j] == s[i+1]: | ||
p[i+1] = j+1 | ||
else: | ||
p[i+1] = 0 | ||
return p | ||
|
||
def funk(s, t, m): | ||
if 1 in t: | ||
for i in range(len(s)): | ||
if t[i] == 1: | ||
m.append(i) | ||
k = s[:m[-1]] | ||
else: | ||
k = s | ||
[print(len(s)// len(k)) if s == k*(len(s)//len(k)) else print(1)] | ||
|
||
S = input() | ||
T = fun(S) | ||
|
||
mass = [] | ||
|
||
funk(S, T, mass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def min_len(t): | ||
kek = 1 | ||
p = [0]*len(t) | ||
for i in range(len(t)-1): | ||
j = p[i] | ||
while t[j] != t[i+1] and j > 0: | ||
j = p[j-1] | ||
if t[j] == t[i+1]: | ||
p[i+1] = j+1 | ||
else: | ||
p[i+1] = 0 | ||
if p[i+1] < 2: | ||
kek = i+1 | ||
return kek | ||
|
||
T = input() | ||
print(min_len(T)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
n = input() #переменная принимающая значения | ||
stack = [] # добавляем пустой стек | ||
k = 0 # создаем счетчик | ||
for i in n: | ||
if i == '(': | ||
stack.append(i) #добавляем в стек | ||
elif i == ')': | ||
if stack: | ||
stack.pop() #очищаем стек | ||
else: | ||
k += 1 | ||
print(k+len(stack)) #выводим |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from collections import deque | ||
|
||
N = int(input()) # вводим количество вагонов в поезде | ||
A = deque(list(map(int, input().split(maxsplit=N)))) #создаем очередь с установленым размером N | ||
B = [] | ||
Toopic = [] | ||
kolvo = list(range(1, N+1)) #кол-во вагонов | ||
|
||
|
||
while A: | ||
if not Toopic or Toopic[-1] > A[0]: | ||
Toopic.append(A.popleft()) #добавляет в Toopic первый удаленный элемент из A | ||
if A and Toopic[-1] < A[0]: | ||
B.append(Toopic.pop()) #добавляет в B последний удаленный элемент из Toopic | ||
|
||
while Toopic: | ||
B.append(Toopic.pop()) #добавляет в B последний удаленный элемент из Toopic | ||
if B == kolvo: | ||
print("YES") | ||
else: | ||
print("NO") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
N = int(input()) # количество элементов в массиве | ||
n = list(map(int, input().split(maxsplit = N))) #создаем очередь с установленым размером N | ||
stack = [] | ||
index = [0]*N | ||
for i in range(N-1, -1, -1): | ||
while stack and n[stack[-1]] >= n[i]: | ||
stack.pop() #удаляем последний элемент в стеке | ||
index[i] = stack[-1] if stack else -1 # если есть ближайшее справа строго меньшего числа,то выводим,иначе -1 | ||
stack.append(i) #добавляем в стек | ||
|
||
print(*index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def min(N, K, arr): #вызываем функцию | ||
stack = [] #создаем пустой стек | ||
for i in range(K): | ||
while stack and arr[i] <= arr[stack[-1]]: | ||
stack.pop() #удаляем последний элемент | ||
stack.append(i) | ||
for i in range(K, N): | ||
print(arr[stack[0]]) #выводим элемент списка arr | ||
while stack and arr[i] <= arr[stack[-1]]: | ||
stack.pop() | ||
while stack and i - K >= stack[0]: | ||
stack.pop(0) | ||
stack.append(i) #добавляем в стек | ||
print(arr[stack[0]]) | ||
|
||
def main(): | ||
N, K = map(int, input().split()) | ||
arr = list(map(int, input().split())) | ||
min(N, K, arr) | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class Node: | ||
def __init__(self, data): | ||
self.data = data | ||
self.left = None | ||
self.right = None | ||
|
||
def add(self, value): | ||
if self.data == value: | ||
return | ||
if value<self.data: | ||
if self.left: | ||
self.left.add(value) | ||
else: | ||
self.left = Node(value) | ||
else: | ||
if self.right: | ||
self.right.add(value) | ||
else: | ||
self.right = Node(value) | ||
|
||
def find_forcs(self): | ||
if self.left: | ||
self.left.find_forcs() | ||
if (self.left and not self.right) or (not self.left and self.right): | ||
print(self.data,) | ||
if self.right: | ||
self.right.find_forcs() | ||
|
||
|
||
def build_tree(elements): | ||
root = Node(elements[0]) | ||
for i in range(1, len(elements)): | ||
root.add(elements[i],) | ||
return root | ||
|
||
|
||
def main(): | ||
elements = list(map(int, input().split())) | ||
elements =elements[:-1] | ||
tree = build_tree(elements) | ||
tree.find_forcs() | ||
|
||
|
||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мда... как же у Вас код сработал, если у Вас ошибки в 25 и 33 строке?