24 lines
455 B
Python
24 lines
455 B
Python
from functools import cmp_to_key
|
|
|
|
n = int(input())
|
|
|
|
|
|
def sorting_method(a, b):
|
|
if ord(a[0]) > ord(b[0]):
|
|
return 1
|
|
elif ord(a[0]) < ord(b[0]):
|
|
return -1
|
|
elif ord(a[1]) > ord(b[1]):
|
|
return 1
|
|
elif ord(a[1]) < ord(b[1]):
|
|
return -1
|
|
return 0
|
|
|
|
|
|
while n:
|
|
names = sorted([input() for _ in range(n)], key=cmp_to_key(sorting_method))
|
|
for name in names:
|
|
print(name)
|
|
print()
|
|
n = int(input())
|