文章
81
粉丝
2
获赞
493
访问
9.5k
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp_up(pair<string,int> a, pair<string,int> b){
return a.second < b.second;
}
bool cmp_down(pair<string,int> a, pair<string,int> b){
return a.second > b.second;
}
int main(){
int n, x;
while(cin >> n >> x){
vector<pair<string,int> > v;
for(int i = 0; i < n; i++){
string name;
int grade;
cin >> name >> grade;
v.push_back(make_pair(name, grade));
}
if(x == 0)
stable_sort(v.begin(), v.end(), cmp_down);
else
stable_sort(v.begin(), v.end(), cmp_up);
for(int i = 0; i < n; i++){
cout << v[i].first << " " << v[i].second << endl;
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发