首页 > 试题广场 >

日志排序

[编程题]日志排序
  • 热度指数:12238 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
有一个网络日志,记录了网络中计算任务的执行情况,每个计算任务对应一条如下形式的日志记录: “hs_10000_p”是计算任务的名称, “2007-01-17 19:22:53,315”是计算任务开始执行的时间“年-月-日 时:分:秒,毫秒”, “253.035(s)”是计算任务消耗的时间(以秒计) hs_10000_p 2007-01-17 19:22:53,315 253.035(s) 请你写一个程序,对日志中记录计算任务进行排序。 时间消耗少的计算任务排在前面,时间消耗多的计算任务排在后面。 如果两个计算任务消耗的时间相同,则将开始执行时间早的计算任务排在前面。

输入描述:
日志中每个记录是一个字符串,每个字符串占一行。最后一行为空行,表示日志结束。日志中最多可能有10000条记录。
计算任务名称的长度不超过10,开始执行时间的格式是YYYY-MM-DD HH:MM:SS,MMM,消耗时间小数点后有三位数字。
计算任务名称与任务开始时间、消耗时间之间以一个或多个空格隔开,行首和行尾可能有多余的空格。


输出描述:
排序好的日志记录。每个记录的字符串各占一行。
输入的格式与输入保持一致,输入包括几个空格,你的输出中也应该包含同样多的空格。
示例1

输入

hs_10000_p   2007-01-17 19:22:53,315     253.035(s)
hs_10001_p   2007-01-17 19:22:53,315     253.846(s)
hs_10002_m   2007-01-17 19:22:53,315     129.574(s)
hs_10002_p   2007-01-17 19:22:53,315     262.531(s)
hs_10003_m   2007-01-17 19:22:53,318     126.622(s)
hs_10003_p   2007-01-17 19:22:53,318     136.962(s)
hs_10005_m   2007-01-17 19:22:53,318     130.487(s)
hs_10005_p   2007-01-17 19:22:53,318     253.035(s)
hs_10006_m   2007-01-17 19:22:53,318     248.548(s)
hs_10006_p   2007-01-17 19:25:23,367    3146.827(s)

输出

hs_10003_m   2007-01-17 19:22:53,318     126.622(s)
hs_10002_m   2007-01-17 19:22:53,315     129.574(s)
hs_10005_m   2007-01-17 19:22:53,318     130.487(s)
hs_10003_p   2007-01-17 19:22:53,318     136.962(s)
hs_10006_m   2007-01-17 19:22:53,318     248.548(s)
hs_10000_p   2007-01-17 19:22:53,315     253.035(s)
hs_10005_p   2007-01-17 19:22:53,318     253.035(s)
hs_10001_p   2007-01-17 19:22:53,315     253.846(s)
hs_10002_p   2007-01-17 19:22:53,315     262.531(s)
hs_10006_p   2007-01-17 19:25:23,367    3146.827(s)
头像 wbc990512
发表于 2021-01-25 22:21:24
看到大佬的代码学会了sscanf #include<stdio.h> #include <stdlib.h> #include<string.h> typedef struct{ char s[100]; char name[20]; ch 展开全文
头像 湖畔竹影12138
发表于 2024-01-10 11:37:42
//参考题解给的iostream便于处理字符串 #include <iostream> #include<string> #include<algorithm> #include<sstream> using namespace std; struct 展开全文
头像 小花Student
发表于 2024-03-04 20:47:32
#include<iostream> #include<vector> #include<algorithm> //hs_10000_p 2007-01-17 19:22:53,315 253.035(s) std::string Start(std 展开全文
头像 chong_0428
发表于 2024-03-07 22:57:37
datas = [] while True: try: line = input().strip() if not line: break datas.append(line) except EOFError: 展开全文
头像 WsjjsZ
发表于 2023-03-19 17:03:26
#include <iostream> #include <bits/stdc++.h> using namespace std; vector<pair<string,string>> vec; bool cmp(pair<string ,st 展开全文
头像 粉詹眉
发表于 2024-02-04 00:17:35
#include <iostream> #include <sstream> #include <algorithm> using namespace std; const int N=10010; struct record{ string name; 展开全文
头像 程昱同学
发表于 2023-01-20 20:03:24
#include <bits/stdc++.h> #include <sstream> using namespace std; int idx=0; struct d { string name; string start_time; string 展开全文
头像 牛客375632021号
发表于 2024-01-16 14:17:11
#include <iostream> #include <sstream> #include <cstring> #include <string> using namespace std; int i_sign = 0; string s_li 展开全文
头像 西区梭梭树
发表于 2023-03-19 18:35:45
在不知道istringstream类的情况下,处理字符串略显费劲 #include <iostream> #include <algorithm> #include "cstdlib" #include "vector" using namespace std; struc 展开全文
头像 JianJ
发表于 2024-02-29 17:42:56
#include<iostream> #include<sstream> #include<algorithm> #include<cstdio> #include<string> using namespace std; const i 展开全文

问题信息

难度:
80条回答 9196浏览

热门推荐

通过挑战的用户

查看代码