#45550: python


suyueh (suyueh)

學校 : 不指定學校
編號 : 272111
來源 : [125.228.45.241]
最後登入時間 :
2025-04-21 17:28:23
n327. The Tower of Names -- 板橋高中教學題 | From: [101.9.53.130] | 發表日期 : 2025-03-14 22:28

def sort_names(names):
"""Sorts names by length, then alphabetically.

Args:
names: A list of names.

Returns:
A list of names sorted by length, then alphabetically.
"""
names.sort(key=lambda x: (len(x), x)) # Sort by length, then alphabetically
return names

# Get the number of names
n = int(input())

# Get the names
names = []
for _ in range(n):
names.append(input())

# Sort the names
sorted_names = sort_names(names)

# Print the sorted names
for name in sorted_names:
print(name)
 
ZeroJudge Forum