文章
61
粉丝
137
获赞
18
访问
38.4k
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
string name;
int score;
}cj;
bool cmp_dec(cj a,cj b){
return a.score > b.score;
}
bool cmp_asc(cj a,cj b){
return a.score < b.score;
}
int main(){
int n, judge;
cin >> n >>judge;
cj x[n];
for(int i = 0;i < n;i++){
cin >> x[i].name >> x[i].score;
}
if(judge == 0)
stable_sort(x,x+n,cmp_dec);
else if(judge == 1)
stable_sort(x,x+n,cmp_asc);
for(int i = 0;i < n;i++){
cout << x[i].name << " " << x[i].score << endl;
}
return 0;
}
登录后发布评论
要循环输入,这样只能输入一组数据。