'commit'
This commit is contained in:
49
TangDou/XiTi/1361.cpp
Normal file
49
TangDou/XiTi/1361.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user