You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0 KiB

2 years ago
#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;
}