Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def comparator(item_1, item_2):
- # это чтобы числа сравнивать (за числами проще следить, чем за кортежами)
- if isinstance(item_1, int):
- return item_1 > item_2
- # если подан кортеж то это уже компаратор должен поработать
- if (item_1[0] == item_2[0]) and (item_1[1] == item_2[1]):
- return item_1 < item_2
- else:
- return item_1 > item_2
- def quick_sort(arr, l_bound=None, r_bound=None, switches=None):
- l_bound = 0 if l_bound is None else l_bound
- r_bound = len(arr) - 1 if r_bound is None else r_bound
- middle = l_bound + (r_bound - l_bound) // 2
- pivot = arr[middle]
- left = l_bound
- right = r_bound
- if r_bound - l_bound <= 1:
- if comparator(arr[r_bound], arr[l_bound]):
- arr[l_bound], arr[r_bound] = arr[r_bound], arr[l_bound]
- return
- while right > left:
- # while switches != 0:
- # switches = 0
- while comparator(arr[left], pivot) and left < right:
- left += 1
- while comparator(pivot, arr[right]) and left < right:
- right -= 1
- # flag = True if middle in (left, right) else False
- if comparator(arr[right], arr[left]):
- arr[left], arr[right] = arr[right], arr[left]
- # switches += 1
- left += 1
- right -= 1
- # pivot = arr[middle]
- # if switches != 0:
- # left = l_bound
- # right = r_bound
- quick_sort(arr, l_bound, middle)
- quick_sort(arr, middle, r_bound)
- # ввод для тестов на сортировку чисел
- seq = list(map(int, input().split()))
- quick_sort(seq)
- print('моя работа: ', *seq)
- print('стандартная работа:', *sorted(seq, reverse=True))
- """
- почему не сортируются?
- 2 3 13 7 4 18 9 16 10 17 12 5 1 20 6 19 11 14 15 8 → вывод: 20 19 18 17 16 13 10 9 7 15 12 14 11 8 6 5 4 3 2 1
- 11 15 12 6 1 17 7 10 8 18 4 20 14 3 2 5 19 9 16 13 → вывод: 20 19 18 12 17 10 8 7 6 16 15 14 13 4 11 5 9 3 2 1
- 8 18 6 20 4 19 17 3 15 16 11 7 14 9 12 5 10 1 13 2 → вывод: 20 19 18 17 16 15 8 6 4 14 13 12 11 9 10 7 5 3 2 1
- 19 14 5 6 10 20 7 8 4 13 12 16 17 15 18 9 11 1 2 3 → вывод: 20 19 18 17 16 15 14 13 8 12 11 10 9 7 6 5 4 3 2 1
- """
- """
- ввод для задачи
- (раскомментировать, чтобы потестировать вводы по условию; ввод для тестов на сортировку чисел при этом закомментировать)
- n = int(input())
- participants = []
- for participant in range(n):
- line = input().split()
- participants.append((int(line[1]), -int(line[2]), line[0]))
- quick_sort(participants)
- for participant in participants:
- print(participant[2])
- """
Advertisement
Add Comment
Please, Sign In to add comment