文章
81
粉丝
0
获赞
275
访问
10.6k
#include<bits/stdc++.h>
using namespace std;
struct stu{
string n;
int num;
stu(string a,int b){
n=a;
num=b;
}
};
bool big(stu a,stu b){
return a.num>b.num;
}
bool small(stu a,stu b){
return a.num<b.num;
}
int main(){
int n;
int order;
while(cin>>n>>order){
vector<stu> s;
for(int i=0;i<n;i++){
string name;
int b;
cin>>name>>b;
s.push_back({name,b});
}
if(order==1){
stable_sort(s.begin(),s.end(),small);
}else{
stable_sort(s.begin(),s.end(),big);
}
for(int i=0;i<n;i++){
cout<<s[i].n<<" "<<s[i].num<<endl;
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发