#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
struct student{
string name;
int score;
};
bool cmp0(const student &a, const student &b){
// 从高到低排序
return a.score > b.score;
}
bool cmp1(const student &a, const student &b){
// 从低到高排序
return a.score < b.score;
}
int main(){
int N, type;
while(cin >> N >> type){
vector<student> stud(N);
for(int i = 0; i < N; i ++){
cin >> stud[i].name >> stud[i].score;
}
if(type == 0)
stable_sort(stud.begin(), stud.end(), cmp0);
else
stable_sort(stud.begin(), stud.end(), cmp1);
for(int i = 0; i < N; i ++){
cout << stud[i].name << " " << stud[i].score << endl;
}
}
return 0;
}
计算机考研复试-1成绩排序
最新推荐文章于 2023-02-25 14:15:04 发布