Advertisement
Guest User

Untitled

a guest
May 25th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. def is_the_first_bigger(a, b):
  2. is_not_changed = True
  3. if len(a) > len(b):
  4. a, b = b, a
  5. is_not_changed = False
  6. if b[:len(a)] == a:
  7. a += b[0]
  8.  
  9. return a > b and is_not_changed
  10.  
  11.  
  12.  
  13. def bubble_sort(a):
  14. curr_unsorted = len(a)
  15. while True:
  16. is_ordered = True
  17. i = 0
  18. while i + 1 < curr_unsorted:
  19. if is_the_first_bigger(a[i], a[i + 1]):
  20. a[i], a[i + 1] = a[i + 1], a[i]
  21. is_ordered = False
  22. i += 1
  23. if is_ordered:
  24. return
  25. else:
  26. curr_unsorted -= 1
  27.  
  28. N = int(input())
  29. a = []
  30. for i in range(N):
  31. a.append(input())
  32. bubble_sort(a)
  33. ans = ''
  34. for i in range(len(a) - 1, -1, -1):
  35. ans += a[i]
  36. print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement