Team allocation

Insert picture description here
Idea: This question only needs to use structure sorting.

#include <bits/stdc++.h>
using namespace std;
struct student{
    
    
    string name; int sore;
};
int cmp(student st1,student st2){
    
    
    return st1.sore<st2.sore;
}
int main()
{
    
    
    int t; cin>>t;
    while(t--){
    
    
        student st[120005];
        int n;cin>>n;
        for(int i=1;i<=3*n;i++){
    
    
            cin>>st[i].name>>st[i].sore;
        }
        sort(st+1,st+3*n+1,cmp);
        int x = 1;
        for(int i=0;i<n;i++){
    
    
            cout<<"ACM-"<<i<<" ";
            cout<<st[x+2].name<<" "<<st[x+1].name<<" "<<st[x].name<<endl;
            x+=3;
        }
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_43811879/article/details/109605864