AcWing 3375. 成绩排序
原题链接
简单
作者:
qpalzmczy
,
2024-04-28 16:36:02
,
所有人可见
,
阅读 1
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e4 + 10;
int n, m;
struct Person
{
string name;
int score;
bool operator<(const Person &t) const
{
return score < t.score;
}
bool operator>(const Person &t) const
{
return score > t.score;
}
} Per[N];
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
{
cin >> Per[i].name >> Per[i].score;
}
if (m == 0)
stable_sort(Per, Per + n, greater<Person>());
else if (m == 1)
stable_sort(Per, Per + n);
for (int i = 0; i < n; i++)
{
cout << Per[i].name << " " << Per[i].score << endl;
}
return 0;
}