-
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
Модуль 2 #127
Open
Natalya1820
wants to merge
4
commits into
Nastasia8:Kurilo_Natalia
Choose a base branch
from
Natalya1820:Kurilo_Natalia
base: Kurilo_Natalia
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
Модуль 2 #127
Changes from all commits
Commits
Show all changes
4 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,10 @@ | ||
n = int(input()) | ||
pairs = [] | ||
for i in range(0, n): | ||
_str = input() | ||
_split = _str.split(' ') | ||
pair = (int(_split[0])), int(_split[1]) | ||
pairs.sort(key=(lambda x: x[0])) | ||
pairs.sort(key=lambda x: x[1], reverse=True) | ||
for i in pairs: | ||
print(str(i[0]) + " " + str(i[1])) |
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,34 @@ | ||
def main(): | ||
n = int(input()) | ||
a = list(map(int,input().split()))[:n] | ||
merge(a,0,len(a)) | ||
print(*a,sep=" ") | ||
def merge(a,start,end): | ||
if end - start > 1: | ||
middle = (start + end) // 2 | ||
merge(a,start,middle) | ||
merge(a,middle,end) | ||
left = a[start:middle] | ||
right = a[middle:end] | ||
internal_sort(a,left,right,start) | ||
print(start + 1, end, a[start], a[end-1]) | ||
def internal_sort(arr,left,right,start): | ||
j = i = 0 | ||
k = start | ||
while i < len(right) and j < len(left): | ||
if left[j] > right[i]: | ||
arr[k] = right[i] | ||
i+=1 | ||
else: | ||
arr[k] = left[j] | ||
j+=1 | ||
k+=1 | ||
while j < len(left): | ||
arr[k] = left[j] | ||
j+=1 | ||
k+=1 | ||
while i < len(right): | ||
arr[k] = right[i] | ||
i+=1 | ||
k+=1 | ||
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,35 @@ | ||
def merge(left, right): | ||
merge_list = [] | ||
i = j = 0 | ||
k = 0 | ||
while i < len(left) and j < len(right): | ||
if left[i] <= right[j]: | ||
merge_list.append(left[i]) | ||
i += 1 | ||
else: | ||
merge_list.append(right[j]) | ||
j += 1 | ||
k += len(left) - i | ||
while i < len(left): | ||
merge_list.append(left[i]) | ||
i += 1 | ||
while j < len(right): | ||
merge_list.append(right[j]) | ||
j += 1 | ||
return merge_list, k | ||
|
||
def MergeSort(A): | ||
|
||
N = len(A) | ||
if N <= 1: | ||
return A, 0 | ||
middle = N//2 | ||
left, left_k = MergeSort(A[0:middle]) | ||
right, right_k = MergeSort(A[middle:N]) | ||
merge_list, k = merge(left, right) | ||
return merge_list, k + left_k + right_k | ||
|
||
N = int(input()) | ||
A = list(map(int, input().split(" "))) | ||
A, result_k = MergeSort(A) | ||
print(result_k) |
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 @@ | ||
n = int(input()) | ||
print(len(set(input().split()))) |
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()) | ||
l = (input().split(' ')) | ||
m = int(input()) | ||
l2 = (input().split(' ')) | ||
for item in range(0, m): | ||
l[int(l2[item]) - 1] = int(l[int(l2[item])-1]) - 1 | ||
for item in l: | ||
if int(item) < 0: | ||
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,34 @@ | ||
numbers = [] | ||
n = int(input()) | ||
for i in range(n): | ||
numbers.append(input()) | ||
|
||
print("Initial array:") | ||
print(', '.join(numbers)) | ||
|
||
count=len(numbers[0]) | ||
Phase = 0 | ||
rang = 10 | ||
for i in range(count-1,-1,-1): | ||
Phase+=1 | ||
print('**********') | ||
print(f'Phase {Phase}') | ||
bucket = [[] for _ in range(rang)] | ||
for j in range (len(numbers)): | ||
bucket [ord(numbers[j][i]) - ord('0')].append(numbers[j]) | ||
for j in range(rang): | ||
if len(bucket[j])==0: | ||
print(f'Bucket {j}: empty') | ||
else: | ||
print("Bucket "+str(j)+": ", end='') | ||
for now in range(len(bucket[j])-1): | ||
print(bucket[j][now], end=', ') | ||
print(bucket[j][len(bucket[j])-1]) | ||
p = 0 | ||
for j in range (rang): | ||
for k in range (len(bucket[j])): | ||
numbers[p]= bucket[j][k] | ||
p+=1 | ||
print('**********') | ||
print("Sorted array:") | ||
print(', '.join(numbers)) |
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,22 @@ | ||
def Preph(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 | ||
|
||
def main(): | ||
s=input() | ||
t=input() | ||
s_t=t+"&"+s | ||
p=Preph(s_t) | ||
for i in range(len(p)): | ||
if p[i]==len(t): | ||
print(i-2*len(t),end=" ") | ||
|
||
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,36 @@ | ||
def get_hash(S,x,P): | ||
hS = 0 | ||
for i in range(len(S)): | ||
hS = (hS*x + ord(S[i]))%P | ||
return hS | ||
|
||
def func(S,t,x,P): | ||
if S != t: | ||
k = 1 | ||
t = t[1:] + t[0] | ||
hS = get_hash(S, x, P) | ||
ht = get_hash(t, x, P) | ||
xt = 1 | ||
for i in range(len(S)-1): | ||
xt = (xt * x) % P | ||
for i in range(len(t)-1): | ||
if hS == ht: | ||
break | ||
else: | ||
ht=(x*(ht-ord(t[i])*xt) + ord(t[i]))%P | ||
k += 1 | ||
if hS == ht: | ||
print(k) | ||
else: | ||
print(-1) | ||
else: | ||
print(0) | ||
|
||
def main(): | ||
S=input() | ||
t=input() | ||
x = 26 | ||
P = 10 ** 9 + 7 | ||
func(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,21 @@ | ||
def prefix(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 | ||
|
||
s = input() | ||
s_t = s+"$"+s | ||
p = prefix(s_t) | ||
p0=p[-1]-p[len(s)-1] | ||
a = len(s)//p0 | ||
if s[:p0]*a == s: | ||
print(a) | ||
else: | ||
print(1) |
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 prefix(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 | ||
|
||
s = input() | ||
s_t = s+"$"+s | ||
a = prefix(s_t) | ||
p0=a[-1]-a[len(s)-1] | ||
print(p0) |
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 @@ | ||
s = input() | ||
stack = [] | ||
k=0 | ||
for i in s: | ||
if i ==")": | ||
if not stack or stack[-1]!="(": | ||
k+=1 | ||
continue | ||
stack.pop() | ||
else: | ||
stack.append(i) | ||
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,20 @@ | ||
N=input() | ||
Railways_A=list(map(int, input().split())) | ||
Railways_B=[] | ||
stack=[] | ||
a=1 | ||
for i in Railways_A: | ||
if i!=a: | ||
stack.append(i) | ||
continue | ||
Railways_B.append(i) | ||
a+=1 | ||
for j in range(len(stack)): | ||
if stack[-1] == a: | ||
Railways_B.append(a) | ||
stack.pop() | ||
a += 1 | ||
if Railways_B[-1] == int(N): | ||
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,48 @@ | ||
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() |
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.
Наташа, добавьте задачи на Контест.
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.
И еще оставляйте свои комментарии в коде, чтобы я видела, что Вы понимаете, что там написано.
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.
Анастасия Валерьевна, здравствуйте!
Я добавила задания из модуля 5 и 6. И отправила несколько заданий на Контесте.
Надеюсь, всё отправилось без проблем)