思路

这题考的应该是自己写一个排序的规则,可以写一个cmp函数,像这样:

bool cmp (const  node &A,const node &B){
        if(A.h != B.h) return A.h < B.h;
        if(A.m != B.m) return A.m < B.m;
        return A.s < B.s;
    }

这个函数用法直接 sort(q,q+n,cmp);
排序规则就是如果返回true表示A应该排在B前面,false表示A应该排再B后面

或者重载 < 号,就像我下面的代码

ps:如果老记不得返回true是谁排在谁前面可以自己输入几个数再输出排序后的测一下

代码

#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define pll pair<ll,ll>
#define INF 0x3f3f3f3f
const int mod = 1e9+7;
const int maxn = 10005;
#define stop system("pause")
inline ll read(){
    ll s = 0, w = 1; char ch = getchar();
    while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}
struct node{
    int h,m,s;
    bool operator < (const  node &A) const {
        if(h != A.h) return h < A.h;
        if(m != A.m) return m < A.m;
        return s < A.s;
    }
}q[5005];
int main(){
    int n = read();
    for(int i = 0 ; i < n ; ++i){
        q[i].h = read();
        q[i].m = read();
        q[i].s = read();
    }
    sort(q,q+n);
    for(int i = 0 ; i < n ; ++i){
        cout<<q[i].h<<" "<<q[i].m<<" "<<q[i].s<<endl;
    }
}