华为机考入门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 软件工程小施同学

相关推荐
Y1nhl2 小时前
力扣_二叉树的BFS_python版本
python·算法·leetcode·职场和发展·宽度优先
向阳逐梦3 小时前
PID控制算法理论学习基础——单级PID控制
人工智能·算法
2zcode3 小时前
基于Matlab多特征融合的可视化指纹识别系统
人工智能·算法·matlab
Owen_Q3 小时前
Leetcode百题斩-二分搜索
算法·leetcode·职场和发展
矢志航天的阿洪4 小时前
蒙特卡洛树搜索方法实践
算法
UnderTheTime4 小时前
2025 XYD Summer Camp 7.10 筛法
算法
zstar-_4 小时前
Claude code在Windows上的配置流程
笔记·算法·leetcode
圆头猫爹4 小时前
第34次CCF-CSP认证第4题,货物调度
c++·算法·动态规划
秋说4 小时前
【PTA数据结构 | C语言版】出栈序列的合法性
c语言·数据结构·算法
用户40315986396635 小时前
多窗口事件分发系统
java·算法