逻辑算法题

磁盘的容量单位有M、G、T,其关系为 1T = 1000G、1G = 1000M,
如样例所示先输入磁盘的个数,再依次输入磁盘的容量大小,然后按照从小到大的顺序对磁盘容量进行排序并输出。
相同大小的先输入的先输出

输入
3
20M
1T
300G
输出
20M
300G
1T
------------------------------------------------------------------------------------------------------
import sys
N = int(sys.stdin.readline().strip())
res = {}
Mnum = 0
Gnum = 0
Tnum = 0
Anum = 0
for i in range(N):
    tmp = 0
    Mnum =0
    Gnum = 0
    Tnum = 0
    line = sys.stdin.readline().strip()
    for value in range(len(line)):
        if line[value] == 'M':
            Mnum += int(line[tmp:value])
            tmp = value+1
        if line[value] == 'G':
            Gnum += int(line[tmp:value])
            tmp = value+1
        if line[value] == 'T':
            Tnum += int(line[tmp:value])
            tmp = value+1
    Anum = Tnum*1024*1024 + Gnum*1024 + Mnum
    res[line] = Anum
print("res = ", res)
pri = sorted(res.items(), key=lambda x: x[1])
for i in range(len(pri)):
    print(pri[i][0])
上一篇:go读取日志tailf


下一篇:Command line is too long问题解决