题解 | #日志排序#

日志排序

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

//参考题解给的iostream便于处理字符串
#include <iostream>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
struct record
{
    string name;
    string startDay;
    string startTime;
    double costTime;
    string line;
};
bool cmp(record r1,record r2)
{
    if(r1.costTime!=r2.costTime)return r1.costTime<r2.costTime;
    else 
    {
        if(r1.startDay!=r2.startDay)return r1.startDay<r2.startDay;
        else return r1.startTime<r2.startTime;
    }
}
int main() {
    record r[10000];
    int i=0;
    string s;
    while (getline(cin,s)) 
    { 
        r[i].line=s;
        istringstream lineStream(s);
        lineStream >>r[i].name>>r[i].startDay>>r[i].startTime>>r[i].costTime;
        //cout<<r[i].line<<endl;
        /*
        cout<<"i="<<i<<endl;
        cout<<r[i].name<<" "<<r[i].startDay<<" "<<r[i].startTime
    <<" "<<r[i].costTime<<endl;
*/
        i++;
    }
    sort(r,r+i,cmp);
    for(int j=0;j<i;j++)
    {
        cout<<r[j].line<<endl;
        /*
        cout<<"test"<<endl;
        cout<<r[i].name<<" "<<r[i].startDay<<" "<<r[i].startTime
    <<" "<<r[i].costTime<<endl;
    */
    }
}
// 64 位输出请用 printf("%lld")

全部评论
适合我
点赞 回复 分享
发布于 2024-03-21 01:13 河南

相关推荐

昨天 11:42
江西农业大学 C++
点赞 评论 收藏
分享
05-16 11:16
已编辑
东华理工大学 Java
牛客73769814...:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
牛客创作赏金赛
点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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