Advertisement
Falexom

Untitled

Jan 18th, 2023
1,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1.  
  2. def convert_ord(lst):   # ну, я пытался изобрести сортировку сравнением с линейной сложностью :)
  3.     ords = []
  4.     for i in lst:
  5.         ords.append(ord(i))
  6.     return ords
  7.  
  8.  
  9. def remove_common(lst):
  10.     unique = []
  11.     for i in lst:
  12.         if i not in unique:
  13.             unique.append(i)
  14.     return unique
  15.  
  16.  
  17. def find_max(lst):
  18.     max = 0
  19.     for i in lst:
  20.             if i > max:
  21.                 max = i
  22.     return max
  23.  
  24.  
  25. def find_min(lst):
  26.     min = 100000000
  27.     for i in lst:
  28.             if i < min:
  29.                 min = i
  30.     return min
  31.  
  32. def zero_push(lst):
  33.     zeros = []
  34.     for i in range(len(lst)):
  35.         zeros.append(0)
  36.     return zeros
  37.  
  38. def remove_zero(lst):
  39.     res = []
  40.     for i in lst:
  41.         if i != 0:
  42.             res.append(i)
  43.     return res
  44.  
  45. def compare_elements(lst):
  46.     big = []
  47.     small = []
  48.     for i in range(1, len(lst)):
  49.         if lst[i] < lst[i-2] and lst[i] not in big:
  50.             small.append(lst[i])
  51.         if lst[i] > lst[i-2] and lst[i] not in small:
  52.             big.append(lst[i])
  53.    
  54.    
  55.     return small + big
  56.        
  57.  
  58. asc_str = "ghfjhvlmayhdsopleznshix"
  59. ords = convert_ord(asc_str)
  60. ords = remove_common(ords)
  61. max = find_max(ords)
  62. min = find_min(ords)
  63. zeros = zero_push(ords)
  64. zeros[0] = min
  65. zeros[-1] = max
  66.  
  67. middle = int(len(ords)/2)
  68. first_half = zeros[:middle]
  69. second_half = zeros[middle:]
  70.  
  71. for i in ords:
  72.     if i not in zeros:
  73.         if (max % i) > (i % min):
  74.             first_half.append(i)
  75.         else:
  76.             second_half.append(i)
  77.  
  78. first_half = remove_zero(first_half)
  79. second_half = remove_zero(second_half)
  80.  
  81. first_half = compare_elements(first_half)
  82. second_half = compare_elements(second_half)
  83.  
  84. all = first_half + second_half
  85.  
  86. print(all)  # получилось ровным счетом никак :)
  87.  
  88. # ну яндекс, ну придумали задачу
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement