AcWing 1478. 签到与签出
原题链接
简单
作者:
王小强
,
2021-03-16 15:31:20
,
所有人可见
,
阅读 250
简单的排个序
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int m;
string id, in_time, out_time;
// 把时间(24小时制)转换成整数(以秒为单位)
int conv(const string t) {
const int h = stoi(t.substr(0, 2));
const int m = stoi(t.substr(3, 2));
const int s = stoi(t.substr(6, 2));
return h * 3600 + m * 60 + s;
}
int main(int argc, char** argv) {
cin >> m;
vector<pair<int, string>> sign_in, sign_out;
while (m--) {
cin >> id >> in_time >> out_time;
sign_in.emplace_back(conv(in_time), id);
sign_out.emplace_back(conv(out_time), id);
}
sort(begin(sign_in), end(sign_in));
sort(begin(sign_out), end(sign_out));
cout << sign_in.front().second << ' ' << sign_out.back().second << endl;
return 0;
}