题解 | #开门人和关门人#
开门人和关门人
https://www.nowcoder.com/practice/a4b37b53a44d454ab0834e1517983215
#include <bits/stdc++.h> using namespace std; typedef struct People{ string num; string open_time; string close_time; }People; vector<People> p; bool cmp_open(People p1, People p2){ return p1.open_time < p2.open_time; } bool cmp_close(People p1, People p2){ return p1.close_time > p2.close_time; } int main(){ int n; cin >> n; for (int i=0; i<n; i++){ string num; string open_time; string close_time; cin >> num >> open_time >> close_time; p.push_back({num, open_time, close_time}); } sort(p.begin(), p.end(), cmp_open); cout << p[0].num << " "; sort(p.begin(), p.end(), cmp_close); cout << p[0].num << endl; return 0; }