Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_the_first_bigger(a, b):
- is_not_changed = True
- if len(a) > len(b):
- a, b = b, a
- is_not_changed = False
- if b[:len(a)] == a:
- a += b[0]
- return a > b and is_not_changed
- def bubble_sort(a):
- curr_unsorted = len(a)
- while True:
- is_ordered = True
- i = 0
- while i + 1 < curr_unsorted:
- if is_the_first_bigger(a[i], a[i + 1]):
- a[i], a[i + 1] = a[i + 1], a[i]
- is_ordered = False
- i += 1
- if is_ordered:
- return
- else:
- curr_unsorted -= 1
- N = int(input())
- a = []
- for i in range(N):
- a.append(input())
- bubble_sort(a)
- ans = ''
- for i in range(len(a) - 1, -1, -1):
- ans += a[i]
- print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement