AcWing 3375. 成绩排序
原题链接
简单
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int N = 1e3+10;
int t,n,m,k,l,r,op,x,y;
string st;
struct nd{
string name;
int score;
bool operator<(const nd&nd1)const{
if(k){
return score<nd1.score;
}else{
return score>nd1.score;
}
}
};
nd ndd[N];
void solve(){
cin>>n>>k;
for(int i = 1;i<=n;i++){
cin>>ndd[i].name>>ndd[i].score;
}
stable_sort(ndd+1,ndd+1+n);
for(int i = 1;i<=n;i++){
cout<<ndd[i].name<<" "<<ndd[i].score<<"\n";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}