文章
211
粉丝
1
获赞
1144
访问
39.7k
#include<bits/stdc++.h>
using namespace std;
struct node{
string name;
int score;
};
bool cmp(node a,node b){
return a.score < b.score;
}
bool rcmp(node a,node b){
return a.score > b.score;
}
int main(){
int n;
while(cin >> n){
vector<node> stu(n);
int p;
cin >> p;
for(int i=0;i<n;i++)
cin >> stu[i].name >> stu[i].score;
if(p == 1){
stable_sort(stu.begin(),stu.end(),cmp);
for(auto it:stu)
cout << it.name << " " << it.score << endl;
}
else{
stable_sort(stu.begin(),stu.end(),rcmp);
for(auto it:stu)
cout << it.name << " " << it.score << endl;
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发