Falexom

Untitled

May 2nd, 2023
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. def chet_nechet(row):   # я чуть не ебанулся пока делал эту задачу
  2.     row.insert(0, 0)
  3.     left = 1
  4.     right = len(row) - 1
  5.     tag = 0
  6.     output = 0
  7.     while left < right:
  8.         if (((left % 2 != 0) and (row[left] % 2 != 0)) and ((right % 2 != 0) and (row[right] % 2 != 0))) or (
  9.                 ((left % 2 == 0) and (row[left] % 2 == 0)) and ((right % 2 == 0) and (row[right] % 2 == 0))):
  10.             left += 1
  11.             right -= 1
  12.  
  13.         if (tag == 1) and (((left % 2 != 0 and row[left] % 2 == 0) or (left % 2 == 0 and row[left] % 2 != 0)) or
  14.                            ((right % 2 != 0 and row[right] % 2 == 0) or (right % 2 == 0 and row[right] % 2 != 0))):
  15.             tag = 2
  16.             break
  17.  
  18.         if ((right % 2 == 0) and (row[right] % 2 == 0)) or ((right % 2 != 0) and (row[right] % 2 != 0)):
  19.             right -= 1
  20.  
  21.         if ((left % 2 == 0) and (row[left] % 2 == 0)) or ((left % 2 != 0) and (row[left] % 2 != 0)):
  22.             left += 1
  23.  
  24.         if ((left % 2 != 0) and (row[left] % 2 == 0) or (left % 2 == 0) and (row[left] % 2 != 0)) and \
  25.                 ((right % 2 != 0) and (row[right] % 2 == 0) or (right % 2 == 0) and (row[right] % 2 != 0)) and (left != right):
  26.             if tag == 0:
  27.                 buf = row[right]
  28.                 row[right] = row[left]
  29.                 row[left] = buf
  30.                 tag = 1
  31.  
  32.     if tag == 0 or tag == 2:
  33.         output = '-1 -1'
  34.         return output
  35.     if tag == 1:
  36.         output = row
  37.         output = output[1:]
  38.         output = [str(i) for i in output]
  39.         output_str = ' '.join(output)
  40.         return output_str
  41.  
  42.  
  43. def interface():
  44.     sher = int(input())
  45.     people = input()
  46.     people = people.split()
  47.     people = [int(i) for i in people]
  48.     print(chet_nechet(people))
  49.  
  50.  
  51. if __name__ == '__main__':
  52.     interface()
  53.  
Add Comment
Please, Sign In to add comment