这题第一次提交即AC
题意
给若干个包含ID、进入时间和离开时间的记录,找出最早进入的ID和最晚离开的ID
思路
结构体排序两次即可
AC代码
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct person{
string id;
int enter,leave;
};
bool cmp1(person a,person b){
return a.enter<b.enter;
}
bool cmp2(person a,person b){
return a.leave>b.leave;
}
int main(){
int M;
string name;
int h,m,s;
scanf("%d",&M);
vector<person> p(M);
for(int i=0;i<M;i++){
cin>>p[i].id;
scanf("%d:%d:%d",&h,&m,&s);
p[i].enter = h*3600+m*60+s;
scanf("%d:%d:%d",&h,&m,&s);
p[i].leave = h*3600+m*60+s;
}
sort(p.begin(),p.end(),cmp1);
cout<<p[0].id<<" ";
sort(p.begin(),p.end(),cmp2);
cout<<p[0].id;
return 0;
}