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

相关推荐
hansang_IR5 小时前
【记录】「SCOI2016」三道模拟赛/26.7.12
c++·算法
千逐685 小时前
HarmonyOS 实战 | @State 不神秘——变量一变界面就跟着变
华为·harmonyos·鸿蒙
退休倒计时5 小时前
【每日一题】LeetCode 39. 组合总和 TypeScript
算法·leetcode·typescript
不是az5 小时前
力控相关知识点
算法·机器学习·最小二乘法
战血石LoveYY6 小时前
Integer类型超限,导致数据异常
java·算法
紫金修道6 小时前
PnP算法介绍(Perspective-n-Point)
算法
froyoisle7 小时前
CSP 真题解析:[CSP-J 2019-T4] 加工零件
c++·算法·bfs·csp-j·算法竞赛·信息学·信奥赛
兰令水7 小时前
hot100【acm版】【2026.7.13打卡-java版本】
java·开发语言·数据结构·算法·leetcode·面试
Tisfy7 小时前
LeetCode 1291.顺次数:打表/枚举
算法·leetcode·题解·枚举·遍历
ysa0510308 小时前
【板子】拓扑排序
c++·算法·图论·板子