AcWing 3375. 成绩排序
原题链接
简单
作者:
Hey_86
,
2024-04-05 17:44:08
,
所有人可见
,
阅读 4
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e3+10;
int n,flag;
vector<pair<string,int>> st;
bool cmp1(const pair<string,int> &a, const pair<string,int> &b){
return a.second > b.second;
}
bool cmp(const pair<string,int> &a, const pair<string,int> &b){
return a.second < b.second;
}
int main(){
cin >> n;
cin >> flag;
while(n--) {
string name;
int grade;
cin >> name >> grade;
st.push_back({name,grade});
}
if(flag) stable_sort(st.begin(),st.end(),cmp);
else stable_sort(st.begin(),st.end(),cmp1);
for(auto x:st) cout<<x.first<<" "<<x.second<<endl;
}