AC
2024-04-16 22:44:50
发布于:江西
9阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct Person {
string name;
int age;
int registrationOrder;
// 定义比较函数,按照医院处理规则排序
bool operator<(const Person& other) const {
// 优先级比较:年龄大的优先,年龄相同则挂号顺序小的优先
//同级处理,按挂号顺序
if(age > 60 && other.age > 60) return registrationOrder < other.registrationOrder;
//不同级按年龄
else if(age > 60 || other.age > 60){
if (age > other.age) {
return true;
}
}else{
//都小于60按挂号顺序
return registrationOrder < other.registrationOrder;
}
return false;
}
void cins(){
cin >> name >> age >> registrationOrder;
}
void couts(){
cout << name << endl;
}
};
int main() {
int n;
cin >> n;
vector<Person> people(n);
for (int i = 0; i < n; ++i) {
people[i].cins();
}
// 按照规则排序
sort(people.begin(), people.end());
// 输出接待顺序
for (int i = 0; i < n; ++i) {
people[i].couts();
}
return 0;
}
这里空空如也
有帮助,赞一个