题解 | #日志排序#

日志排序

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

#include <iostream>
#include <sstream>
#include <algorithm>
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;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
fRank1e:吓得我不敢去外包了,但是目前也只有外包这一个实习,我还要继续去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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