一、题目
给定 n 个字符串,请对 n 个字符串按照字典序排列。
数据范围:
1
≤
n
≤
1000
1\le n\le 1000
1≤n≤1000 ,字符串长度满足:
1
≤
l
e
n
≤
100
1\le len\le 100
1≤len≤100
输入描述:
输入第一行为一个正整数 n(
1
≤
n
≤
1000
1\le n\le 1000
1≤n≤1000),下面 n 行为 n 个字符串(字符串长度≤100),字符串中只含有大小写字母。
输出描述:
数据输出 n 行,输出结果为按照字典序排列的字符串。
二、示例
输入:9
cap
to
cat
card
two
too
up
boat
boot
输出:boat
boot
cap
card
cat
to
too
two
up
三、代码
while True:
try:
nums = int(input())
temp = []
for i in range(nums):
words = input()
temp.append(words)
temp.sort()
print('\n'.join(temp))
except:
break
四、算法说明
首先获得字符串的个数;
将所有的字符串存入列表temp
,并进行排序;
将列表temp
用换行\n
连接,打印输出。
胡萝卜
我不知道将去向何方,但我已在路上! |
---|
时光匆匆,虽未曾谋面,却相遇于斯,实在是莫大的缘分,感谢您的到访 ! |