# 比较两个单词的先后,如果 word1 在 word2 前面则返回 True, 否则返回 False
def cmp(word1, word2):
if not word1:
return True
elif not word2:
return False
if word1[0] == word2[0]:
w1, w2 = word1[1:], word2[1:]
tag = cmp(w1, w2)
return tag
elif word1[0] < word2[0]:
return True
return False
# 通过 cmp() 方法使用快排
def quick_sort(array):
if not array:
return array
pivot = array.pop()
greater, lesser = [], []
for element in array:
if cmp(element, pivot):
lesser.append(element)
else:
greater.append(element)
return quick_sort(lesser) + [pivot] + quick_sort(greater)
count = int(input())
words = []
for i in range(count):
words.append(input())
for i in quick_sort(words):
print(i)
# 方法二:使用 python list.sort()
# count = int(input())
# words = []
# for i in range(count):
# words.append(input())
# words.sort()
# for i in words:
# print(i)