自定义函数:当比较函数返回值为true,表示第一个参数会排列在第二个参数前面,反之亦然

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX=100;

struct Student{
    int number;
    int score;
};

Student arr[MAX];

bool Compare(Student X, Student Y){
    if(X.score == Y.score)
        return X.number < Y.number;
    else
        return X.score<Y.score;
}


int main(){
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;i++)
        scanf("%d%d",&arr[i].number,&arr[i].score);
    sort(arr, arr+n,Compare);
    for(int i=0;i<n;i++)
        printf("%d %d\n",arr[i].number,arr[i].score);
    return 0;
}