难点一 : 如何储存三个数的形式呢?
vector<pair<pair<int, int>, int>> times;
难点二 : 如何进行升序排列和降序排列的const写法呢
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main (){
int n ;
cin >> n;
vector<pair<pair<int, int>, int>> times;
for (int i = 0; i < n; i++) {
int h, m, s;
cin >> h >> m >> s;
times.push_back({{h, m}, s});
}
sort(times.begin(), times.end(), [](const auto& a, const auto& b) {
if (a.first.first != b.first.first)
return a.first.first < b.first.first;
if (a.first.second != b.first.second)
return a.first.second < b.first.second;
return a.second < b.second; //上述的<改成>就会进行降序排列
});
for (const auto& time : times) {
cout << time.first.first << " " << time.first.second << " " << time.second << endl;
}
return 0;
}