基本思想:
1.使用类输入,构造成一个序列;
2.直接两次排序;
关键点:
注意sort和cmp的返回值和构造问题;
1 #include<iostream>
2 #include<stdlib.h>
3 #include<stdio.h>
4 #include<vector>
5 #include<string>
6 #include<math.h>
7 #include<algorithm>
8 using namespace std;
9 using std::vector;
10 struct student{
11 char id[16];
12 int sh;
13 int sm;
14 int ss;
15 int eh;
16 int em;
17 int es;
18 };
19 vector<student>vec;
20 bool flag = false;
21 bool cmp(student a, student b) {
22 if (flag) {
23 if (a.sh != b.sh)
24 return a.sh > b.sh;
25 else if (a.sm != b.sm)
26 return a.sm > b.sm;
27 else
28 return a.ss > b.ss;
29 }
30 else {
31 if (a.eh != b.eh)
32 return a.eh < b.eh;
33 else if (a.sm != b.sm)
34 return a.em < b.em;
35 else
36 return a.es < b.es;
37 }
38 }
39
40 int main() {
41 int n;
42 scanf("%d", &n);
43 vec.resize(n);
44 //cout << n << endl;
45 for (int i = 0; i < n; i++) {
46 scanf("%s %d:%d:%d %d:%d:%d", vec[i].id, &vec[i].sh, &vec[i].sm, &vec[i].ss, &vec[i].eh, &vec[i].em, &vec[i].es);
47 //cout << "->" << vec[i].id << endl;
48 }
49 sort(vec.begin(), vec.end(), cmp);
50 printf("%s", vec[0].id);
51 flag = true;
52 sort(vec.begin(), vec.end(), cmp);
53 printf(" %s", vec[0].id);
54 system("pause");
55 return 0;
56 }
来源:https://www.cnblogs.com/songlinxuan/p/12188379.html