题解 | #日志排序#

日志排序

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 河南

相关推荐

10-29 15:51
嘉应学院 Java
后端转测开第一人:你把简历的学历改成北京交通大学 去海投1000份发现基本还是没面试
点赞 评论 收藏
分享
gelmanspar...:奖学金删掉,自我评价删掉,简历压缩一下,写一页
如果再来一次,你还会学机...
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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