文章

111

粉丝

1

获赞

737

访问

21.6k

头像
日志排序 题解:c++ ,这题空格很多,哪都是,还是直接分割吧
P1227 北京大学机考题
发布于2026年2月9日 15:39
阅读数 722

#include <bits/stdc++.h>
using namespace std;

struct Log{
    string line;
    string date;
    double time;
};
bool cmp(Log a,Log b){
    if(a.time == b.time)return a.date < b.date;
    return a.time < b.time;
}
int main()
{
    vector<Log> log;
    string line;
    double t;
    while(getline(cin,line) && !line.empty()){
        string old = line;        //原始字符串
        stringstream str(line);   //分割字符串 
        string x,y,z,s;                
        str >> x >> y >> z >> s;
        t = stod(s.substr(0,s.find('(')));
        log.push_back({old,y+z,t}); //存入vector
    }
    sort(log.begin(),log...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发