-
-
Save mikhail-01/512f5a072a49d50929fdbf3ee2372952 to your computer and use it in GitHub Desktop.
Решение задачи 99 на UniLecs
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
""" | |
Задача 99 на UniLecs | |
Решение. Сортируем массив с использованием функции сравнения двух элементов, | |
которая перед сравнением строк разной длины взаимно дополняет их друг другом. | |
""" | |
from functools import cmp_to_key | |
def cmp_elems(x, y): | |
if len(x) != len(y): x, y = x+y, y+x | |
return int(y) - int(x) | |
def solve(arr): | |
return "".join(sorted(arr, key=cmp_to_key(cmp_elems))) | |
test = [ ["123", "124", "56", "90"], | |
["1", "9", "950", "96", "960", "940", "9000", "1", "2"], | |
["5", "56", "560", "570", "550", "540", "7", "22"] ] | |
for arr in test: | |
print(f'arr = {arr}\nAnswer = {solve(arr)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment