文章

5

粉丝

53

获赞

4

访问

1.9k

头像
日志排序 题解:使用sort,将运行时间换为double
P1227 北京大学机考题
发布于2024年2月26日 10:07
阅读数 670

将字符串输入,分割成两部分,为了方便输出,将name存储整个日志,将其中日期和时间分割出来。日期可以直接比大小

#include <iostream>
#include <string>
#include<algorithm>
using namespace std;

typedef struct T{
    string name;
    string data;
    double run;
};

bool cmp(T x,T y){
    if(x.run==y.run)return x.data<y.data;
    else return x.run<y.run;
}

int main(){
    string temp;
    T t[10000];
    int cnt=0;
    while(getline(cin,temp)){
        if(temp=="")break;
        t[cnt].name=temp;
        t[cnt].data=temp.substr(13,23);
        t[cnt].run=stod(temp.substr(36,12));
        cnt++;
    }
    sort(t,t+cnt,cmp);
    for(int i=0;i<cnt;i++)
        cout<<t[i].name<<endl;
}
 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发