题解 | #开门人和关门人#
开门人和关门人
https://www.nowcoder.com/practice/a4b37b53a44d454ab0834e1517983215
#include<iostream> #include<string> #include<vector> #include<map> #include<algorithm> using namespace std; struct info { string id, enter_time, left_time; info(string a, string b, string c) { id = a, enter_time = b, left_time = c; } }; bool cmp1(info a, info b) { return a.enter_time.compare(b.enter_time) < 0; } bool cmp2(info a, info b) { return a.left_time.compare(b.left_time) >0; } int main() { int M; scanf("%d", &M); vector<info>data_list; while (M--) { string id, enter_time, left_time; cin >> id >> enter_time >> left_time; data_list.push_back(info(id, enter_time, left_time)); } sort(data_list.begin(), data_list.end(), cmp1); cout << data_list[0].id << " "; sort(data_list.begin(), data_list.end(), cmp2); cout << data_list[0].id; }