3 solutions

  • 0
    @ 2025-6-9 18:17:00
    #include<bits/stdc++.h>
    using namespace std;
    const int N=110;
    struct Stu{
        string name;
        int sc;
    };
    Stu stu[N];
    bool cmp(stu a,stu b)
    {
        if(a.sc>b.sc) return 1;
    	if(a.sc==b.sc&&a.name<b.name) return 1;
    	return 0; 
    }
    int main()
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>stu[i].name>>stu[i].sc;
        }
        sort(stu+1,stu+n+1,cmp);//将stu[i]到stu[n]按照cmp规则排序
        for(int i=1;i<=n;i++)
        {
            cout<<stu[i].name<<" "<<stu[i].sc<<endl;
        }
        return 0;
    }
    

    Information

    ID
    943
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    1
    Tags
    (None)
    # Submissions
    78
    Accepted
    22
    Uploaded By