题解 | #日志排序#

日志排序

https://www.nowcoder.com/practice/0f64518fea254c0187ccf0ea05019672

#include <iostream>
#include <algorithm>
#include <sstream>

using namespace std;

const int N = 10010;

struct record{
	string name;
	string date;
	string start_time;
	double task_time;
	string line;
}a[N];

bool cmp(record &a,record &b){
	if(a.task_time != b.task_time)return a.task_time < b.task_time;
	else{
		if(a.date != b.date)return a.date < b.date;
		else return a.start_time < b.start_time;
	}
}

int main(){
	string line;
	int i = 0;
	while(getline(cin,line)){
		a[i].line = line;
		stringstream ssin(line);
		ssin>>a[i].name>>a[i].date>>a[i].start_time>>a[i].task_time;//不用管类型,ssin>>读入即可
        i++;
	}
	sort(a,a + i,cmp);
	for(int j = 0;j < i;j ++){
		cout << a[j].line << endl;
	}
	
	return 0;
}

全部评论

相关推荐

05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
群星之怒:不是哥们,你就不好奇瘫痪三十年的老植物人是啥样的吗?
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务