Skip to content
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
33 changes: 33 additions & 0 deletions python/src/module2/conversion_count_ex4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def merge(left,right):
global count
i =0; j = 0; k = 0; c = [0]*(len(left)+len(right))
while k < len(c):
if (j == len(right)) or (i < len(left) and left[i] <= right[j]):
c[k] = left[i]
i+=1
else:
c[k] = right[j]
j+=1
count += len(left)-i
k+=1
return c
def merge_sort(sorted):
if len(sorted) == 1:
return sorted
else:
left_part = sorted[0:len(sorted)//2:1]
right_part = sorted[len(sorted)//2::1]
left_part = merge_sort(left_part)
right_part = merge_sort(right_part)
return merge(left_part,right_part)
if __name__ == "__main__":
input = open("input.txt","r")
arrLen = int(input.readline())
arr = input.readline().split()
count = 0
input.close()
for i in range(0,arrLen,1):
arr[i] = int(arr[i])
arr= merge_sort(arr)
print(count)

32 changes: 32 additions & 0 deletions python/src/module2/merge_sort_ex3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def merge(left,right):
i = 0; j = 0; k = 0; c = [0]*(len(left)+len(right))
while k < len(c):
if (j == len(right)) or (( i < len(left)) and (left[i] <= right[j])):
c[k] = left[i]
i+=1
else:
c[k] = right[j]
j+=1
k+=1
return c
def merge_sort(sort_array,shift = 1):
if len(sort_array) == 1:
return sort_array
else:
shift_ind = len(sort_array)//2
left = sort_array[0:shift_ind:1]
right = sort_array[shift_ind::1]
left = merge_sort(left,shift)
right = merge_sort(right,shift+shift_ind)
result = merge(left,right)
print(shift,shift+len(sort_array)-1,result[0],result[-1])
return result
if __name__ == "__main__":
file = open("input.txt","r")
n = int(file.readline())
array = file.readline().split()
for i in range(0,n,1):
array[i] = int(array[i])
sorted = merge_sort(array)
for i in range(n):
print(sorted[i], end = " ")
6 changes: 6 additions & 0 deletions python/src/module2/num_of_diff_ex5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if __name__ == "__main__":
n = int(input())
array = input().split()
for i in range(0,len(array)):
array[i] = int(array[i])
print(len(set(array)))
25 changes: 25 additions & 0 deletions python/src/module2/pair_sort_ex2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
file = open("input.txt","r")
len_of_array = int(file.readline())
array_of_numbers = []
array_of_prices = []
for i in range (0,len_of_array,1):
string = file.readline().split()
string[0] = int(string[0])
array_of_numbers.append(string[0])
string[-1] = int(string[-1])
array_of_prices.append(string[-1])
file.close()
file = open("output.txt","w")
for i in range(0,len_of_array-1,1):
for j in range(0,len_of_array-1,1):
if int(array_of_prices[j]) == array_of_prices[j+1]:
if int(array_of_numbers[j]) < array_of_numbers[j+1]:
array_of_prices[j] ,array_of_prices[j+1] = array_of_prices[j+1],array_of_prices[j]
array_of_numbers[j] ,array_of_numbers[j+1] = array_of_numbers[j+1],array_of_numbers[j]
else:
if int(array_of_prices[j]) > array_of_prices[j+1]:
array_of_prices[j] ,array_of_prices[j+1] = array_of_prices[j+1],array_of_prices[j]
array_of_numbers[j] ,array_of_numbers[j+1] = array_of_numbers[j+1],array_of_numbers[j]
for i in range(len_of_array-1,-1,-1):
file.write(str(array_of_numbers[i])+" "+str(array_of_prices[i])+"\n")
file.close()
16 changes: 16 additions & 0 deletions python/src/module2/sort_process_ex1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
input = open("input.txt","r")
lenArr = int(input.readline())
arr = input.readline()
arr = arr.split()
input.close()
swap_count = 0
input = open("output.txt","w")
for i in range(0,lenArr-1,1):
for j in range(0,lenArr-1,1):
if int(arr[j]) > int(arr[j+1]):
arr[j] ,arr[j+1] = arr[j+1],arr[j]
input.write(" ".join(arr)+"\n")
swap_count +=1
if swap_count == 0:
input.write("0\n")
input.close()
12 changes: 12 additions & 0 deletions python/src/module2/warehouse_ex6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if __name__ == "__main__":
n = int(input())
goods_count = input().split()
k = int(input())
orders = input().split()
for i in range(0,k):
orders[i] = int(orders[i])
for i in range(0,n):
if orders.count(i+1) > int(goods_count[i]):
print('yes')
else:
print('no')