小白来个python版的:- file = "test.txt"
- result = "res.txt"
- with open(file,"r",encoding="utf8") as f:
- head = f.readline() #读第一行头
- gen = (tuple(int(x) for x in line.split()) for line in f)
- res = sorted(gen,key=lambda x:(x[0],-x[1],x[2],-x[3],x[4])) #多条件排序,取负值按降序
-
- with open(result,"w") as f:
- f.write(head) #写第一行头
- for i in res:
- f.write(" ".join(str(x) for x in i)) #拼接成字符串写入
- f.write("\n")
复制代码 python性能肯定不是最快的,用了7楼CrLf生成的测试数据1W条,运行完成时间是0.33秒左右。 |