python 字符串排序


地址:

https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723?tpId=37&tqId=21237&rp=1&ru=%2Fta%2Fhuawei&qru=%2Fta%2Fhuawei%2Fquestion-ranking&tab=answerKey

 

 1 '''
 2 題目描述
 3 給定n個字符串,請對n個字符串按照字典序排列。
 4 輸入描述:
 5 輸入第一行為一個正整數n(1≤n≤1000),下面n行為n個字符串(字符串長度≤100),字符串中只含有大小寫字母。
 6 輸出描述:
 7 數據輸出n行,輸出結果為按照字典序排列的字符串。
 8 示例1
 9 輸入
10 9
11 cap
12 to
13 cat
14 card
15 two
16 too
17 up
18 boat
19 boot
20 輸出
21 boat
22 boot
23 cap
24 card
25 cat
26 to
27 too
28 two
29 up
30 
31 '''
32 
33 n= int(input())
34 l = []
35 for i in range(n):
36     l.append(input())
37 l.sort()
38 for i in l:
39     print(i)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM