Files
python/TangDou/XiTi/1361.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

50 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
//结构体
struct Person {
string id;
int index;
int age;
};
//对比的方法
/*
用大于号就是从大到小排序,用小于号就是从小到大排序
*/
bool cmp(const Person &x, const Person &y) {
//老年人比较
if (x.age >= 60 && y.age >= 60) {
if (x.age == y.age) {
return x.index < y.index;
}
return x.age > y.age;
}
//A是老年人,B是年轻人
if (x.age >= 60) return true;
//A是年轻人,B是老年人
if (y.age >= 60) return false;
//都是年轻人
return x.index < y.index;
}
int main() {
int n;
cin >> n;
Person *p = new Person[n];
for (int i = 0; i < n; ++i) {
cin >> p[i].id >> p[i].age;
p[i].index = i + 1;
}
//排序
sort(p, p + n, cmp);
//输出
for (int i = 0; i < n; ++i) {
cout << p[i].id << endl;
}
//删除动态指针数组
delete[]p;
return 0;
}