Olegos

Паллиндром из набора чисел

May 16th, 2022 (edited)
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. kit = list(str(input('Набор чисел: ')))
  2. len_pal = int(input('Длина будущего паллиндрома: '))
  3.  
  4. double, max_one = [], []
  5.  
  6. for item in set(kit):
  7.     if kit.count(item) % 2 == 1:
  8.         max_one.extend(item)
  9.         double.extend([item]*((kit.count(item)-1)//2))
  10.  
  11.     else:
  12.         double.extend([item]*(kit.count(item)//2))
  13.  
  14. while len(double)*2 > len_pal-1:
  15.     double.remove(min(double))
  16.  
  17. print(f"{''.join(sorted(double, reverse=True))}{max(max_one)}{''.join(sorted(double))}")
  18.  
Add Comment
Please, Sign In to add comment