AcWing 1478. 签到与签出(麻烦的写法)
原题链接
简单
作者:
Value
,
2020-05-31 12:19:59
,
所有人可见
,
阅读 454
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 16;
struct node{
string id;
int st, ed;
};
node person[N];
int getTime(string s){
int hour, minute, second;
sscanf(s.c_str(), "%d:%d:%d", &hour, &minute, &second);
return hour * 3600 + minute * 60 + second;
}
int way;
bool cmp(node a, node b){
if(way == 1) return a.st < b.st;
else return a.ed > b.ed;
}
int main(){
int n;
cin >> n;
string id, st, ed;
for(int i = 0; i < n; i ++ ){
cin >> id >> st >> ed;
person[i].id = id;
person[i].st = getTime(st);
person[i].ed = getTime(ed);
}
way = 1, sort(person, person + n, cmp);
cout << person[0].id << " ";
way = 2, sort(person, person + n, cmp);
cout << person[0].id << endl;
return 0;
}