题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/7a2f7d304d9e43b1bb2a6e72ed65bf51
#include<iostream>
#include<queue>
#include<string>
using namespace std;
struct stu{
string name;
int age;
int grade;
stu(string s,int a,int g):name(s),age(a),grade(g){}
bool operator<(const stu& student)const{
if(grade==student.grade && name==student.name)
return age>student.age;
else if(grade==student.grade)
return name>student.name;
return grade>student.grade;
}
};
int main(){
int n;
while(cin>>n){
string name;
int age,grade;
priority_queue<stu> pq;
for(int i=0;i<n;i++){
cin>>name>>age>>grade;
pq.push(stu(name,age,grade));
}
while(pq.size()){
cout<<pq.top().name<<" "<<pq.top().age<<" "<<pq.top().grade<<endl;
pq.pop();
}
}
return 0;
}

腾讯音乐娱乐集团公司福利 283人发布