思路
其实本质上就是对签到记录按照签到时间或者签离时间进行排序,第一个签到的开门,最后一个签离的关门,但是如果只是找到最值的话,没必要进行排序,用两个变量记录一下就好了。
#include<iostream> #include<vector> using namespace std; int main(){ int n; while(cin >> n){ string id, signIn, signOut; string openId, closeId; string signInTime = "24:00:00", signOutTime = "00:00:00"; for(int i = 0; i < n; i ++){ cin >> id >> signIn >> signOut; if(signIn < signInTime){ signInTime = signIn; openId = id; } if(signOut > signOutTime){ signOutTime = signOut; closeId = id; } } cout << openId << " " << closeId << endl; } return 0; }