华为机考入门python3--(14)牛客14-字符串排序

分类:列表、排序

知识点:

  1. 字典序排序 sorted(my_list)

题目来自【牛客】

python 复制代码
def sort_strings_by_lex_order(strings):  
    # 使用内置的sorted函数进行排序,默认是按照字典序排序  
    sorted_strings = sorted(strings)  
    # 返回排序后的字符串列表  
    return sorted_strings  


n = int(input().strip())

strings = []
for i in range(n):
    strings.append(input().strip())

sorted_strings = sort_strings_by_lex_order(strings)  

# 输出结果  
for s in sorted_strings:  
    print(s)

by 软件工程小施同学

相关推荐
sali-tec6 小时前
C# 基于halcon的视觉工作流-章66 四目匹配
开发语言·人工智能·数码相机·算法·计算机视觉·c#
小明说Java6 小时前
常见排序算法的实现
数据结构·算法·排序算法
行云流水20197 小时前
编程竞赛算法选择:理解时间复杂度提升解题效率
算法
smj2302_796826528 小时前
解决leetcode第3768题.固定长度子数组中的最小逆序对数目
python·算法·leetcode
cynicme9 小时前
力扣3531——统计被覆盖的建筑
算法·leetcode
core5129 小时前
深度解析DeepSeek-R1中GRPO强化学习算法
人工智能·算法·机器学习·deepseek·grpo
mit6.8249 小时前
计数if|
算法
a伊雪10 小时前
c++ 引用参数
c++·算法
Data_agent10 小时前
1688获得1688店铺列表API,python请求示例
开发语言·python·算法