#include <iostream>
#include <algorithm>
using namespace std;
const int N=1010;
struct Person
{
string name;
int cj;
bool operator> (const Person&t) const //重载运算符
{
return cj>t.cj;
}
bool operator< (const Person&t) const
{
return cj<t.cj;
}
}a[N];
int main()
{
int x,y;
cin>>x>>y;
for(int i=0;i<x;i++) cin>>a[i].name>>a[i].cj;
if(!y) stable_sort(a,a+x,greater<Person>());
else stable_sort(a,a+x);
for(int i=0;i<x;i++) cout<<a[i].name<<' '<<a[i].cj<<endl;
return 0;
}
成绩排序(c++)
于 2024-07-17 13:35:02 首次发布