1 条题解

  • 0
    @ 2025-4-12 19:44:42

    思路分析

    知识点: 结构体,多关键字排序(需提供 cmparecmpare 函数) 直接上代码

    AC代码

    #include<bits/stdc++.h>
    
    using namespace std;
    
    struct node{
        string name;//姓名
        int cj;//成绩
    };
    
    int n;
    node studentt[25];
    bool cmp(node a,node b){
        if(a.cj != b.cj)return a.cj > b.cj;
        /*成绩不一样时,较大者在前*/
        else return a.name < b.name;
        /*成绩相同时,按字典序排序*/
    }
    signed main(){
        cin >> n;
        for(int i = 1 ; i <= n ; i++){
            cin >> studentt[i].name >> studentt[i].cj;
        }
        sort(studentt+1,studentt+n+1,cmp);
        /*
        sort(开始排序的位置,结束排序的位置,比较函数)
        */
        for(int i = 1 ; i <= n ; i++){
            cout << studentt[i].name << ' ' << studentt[i].cj << '\n';
        }
        return 0;
    }
    

    信息

    ID
    36207
    时间
    1000ms
    内存
    512MiB
    难度
    1
    标签
    递交数
    7
    已通过
    4
    上传者