Files
python/TangDou/Mkx/20241103/1.cpp

44 lines
1.0 KiB
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
struct Node {
char name[20];
int s; // 得分
int r; // 排名
int no; // 输入序号
} a[N];
int n;
bool cmp1(Node x, Node y) {
return x.s > y.s; // 按成绩由大到小
}
bool cmp2(Node x, Node y) {
return x.no < y.no; // 按输入次序由小到大
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].name >> a[i].s;
a[i].no = i;
}
sort(a + 1, a + n + 1, cmp1); // 按成绩排序,由大到小
// 已经按成绩由大到小排好序了,现在需要标每个人的排名
a[1].r = 1; // 第一名无可争议
for (int i = 2; i <= n; i++)
if (a[i].s == a[i - 1].s)
a[i].r = a[i - 1].r;
else
a[i].r = i;
// 现在排名的标注已完成,按题目要求重新按输入序排序
sort(a + 1, a + n + 1, cmp2);
for (int i = 1; i <= n; i++)
cout << a[i].name << " " << a[i].r << endl;
return 0;
}