18
作者:
LC_toccc
,
2024-11-11 21:35:33
,
所有人可见
,
阅读 2
一、成绩排名
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
struct Student{
string name;
int grade;
};
//自定义比较函数,实现降序。
bool cmp(Student a, Student b){
return a.grade > b.grade;
}
int main(){
int n;
cin >> n;
vector<Student> students;
while(n--){
Student student;
cin >> student.name >> student.grade;
students.push_back(student);
}
stable_sort(students.begin(), students.end(), cmp);
for(const auto& student : students){
cout << student.name << ' ' << student.grade << endl;
}
return 0;
}