def convert_to_mb(capacity):
# 将容量字符串转换为以MB为单位的值
total_mb = 0
i = 0
while i < len(capacity):
# 提取数字部分
num = 0
while i < len(capacity) and capacity[i].isdigit():
num = num * 10 + int(capacity[i])
i += 1
# 提取单位部分
if i < len(capacity):
unit = capacity[i]
i += 1
if unit == 'T':
total_mb += num * 1024 * 1024
elif unit == 'G':
total_mb += num * 1024
elif unit == 'M':
total_mb += num
return total_mb
def stable_disk_sort(n, disks):
# 将磁盘容量转换为MB并记录原始索引
disk_list = []
for idx, disk in enumerate(disks):
mb = convert_to_mb(disk)
disk_list.append({'original_index': idx, 'capacity': disk, 'mb': mb})
# 按MB值进行稳定排序
disk_list.sort(key=lambda x: x['mb'])
# 按排序后的顺序输出磁盘容量
sorted_disks = [disk['capacity'] for disk in disk_list]
return sorted_disks
# 读取输入
n = int(input())
disks = [input().strip() for _ in range(n)]
# 计算并输出结果
sorted_disks = stable_disk_sort(n, disks)
for disk in sorted_disks:
print(disk)
网站首页 > 技术文章 正文
猜你喜欢
- 2025-04-10 Python版的迷你程序——快速排序(python简单排序)
- 2025-04-10 python序列之列表详解(python中序列和列表)
- 2025-04-10 Python 实现七大排序算法(python排序问题)
- 2025-04-10 Python实现列表排序及连接(python列表排序key)
- 2025-04-10 Python技巧:列表(list)和字典(dict)排序合集
- 2025-04-10 Python 实现【全排列】(python数组全排列)
- 2025-04-10 如何用Python排列数字(python怎么排列数字)
- 263℃Python短文,Python中的嵌套条件语句(六)
- 263℃python笔记:for循环嵌套。end=""的作用,图形打印
- 261℃PythonNet:实现Python与.Net代码相互调用!
- 256℃Python实现字符串小写转大写并写入文件
- 255℃Python操作Sqlserver数据库(多库同时异步执行:增删改查)
- 116℃原来2025是完美的平方年,一起探索六种平方的算吧
- 96℃Python 和 JavaScript 终于联姻了!PythonMonkey 要火?
- 89℃Ollama v0.4.5-v0.4.7 更新集合:Ollama Python 库改进、新模型支持
- 最近发表
- 标签列表
-
- python中类 (31)
- python 迭代 (34)
- python 小写 (35)
- python怎么输出 (33)
- python 日志 (35)
- python语音 (31)
- python 工程师 (34)
- python3 安装 (31)
- python音乐 (31)
- 安卓 python (32)
- python 小游戏 (32)
- python 安卓 (31)
- python聚类 (34)
- python向量 (31)
- python大全 (31)
- python次方 (33)
- python桌面 (32)
- python总结 (34)
- python浏览器 (32)
- python 请求 (32)
- python 前端 (32)
- python验证码 (33)
- python 题目 (32)
- python 文件写 (33)
- python中的用法 (32)