Advertisement
barbos01

depou

Apr 17th, 2022
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. stiva_a = []
  2. stiva_b = []
  3. n = int(input())
  4. for i in range(1, n + 1):
  5.     aux = int(input())
  6.     stiva_a.append(aux)
  7. contor = 1
  8. rezultat = []
  9. p = 1
  10. while stiva_a or stiva_b:
  11.     if stiva_b and stiva_b[-1] == contor:
  12.         stiva_b.pop()
  13.         contor += 1
  14.         rezultat.insert(p + 1, 2)
  15.         rezultat.insert(p + 2, 3)
  16.         p += 2
  17.     else:
  18.         while stiva_a and stiva_a[-1] != contor:
  19.             if stiva_b and stiva_a[-1] >= stiva_b[-1]:
  20.                 break
  21.             stiva_b.append(stiva_a[-1])
  22.             stiva_a.pop()
  23.             rezultat.insert(p + 1, 1)
  24.             rezultat.insert(p + 2, 2)
  25.             p += 2
  26.         if stiva_a[-1] != contor:
  27.             break
  28.         else:
  29.             rezultat.insert(p + 1, 1)
  30.             rezultat.insert(p + 2, 3)
  31.             p += 2
  32.             stiva_a.pop()
  33.             contor += 1
  34. if contor < n:
  35.     print(0)
  36. else:
  37.     print(int((p - 1) / 2))
  38.     print("\n")
  39.     for i in range(len(rezultat)):
  40.         if rezultat[i] == 1:
  41.             print("A ")
  42.         if rezultat[i] == 2:
  43.             print("B ")
  44.         if rezultat[i] == 3:
  45.             print("C ")
  46.         if i % 2 == 1:
  47.             print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement