#include<iostream> #include<algorithm> #include<string> using namespace std; struct str{ int age; string id; int order; }people[105]; bool cmp(const str a,const str b) { if (a.age >= 60 && b.age < 60) { return true; // 老年人优先看病 } else if (a.age < 60 && b.age >= 60) { return false; // 非老年人后看病 } else if (a.age >= 60 && b.age >= 60) { if (a.age == b.age) { return a.order < b.order; // 年龄相同按登记顺序排序 } else { return a.age > b.age; // 老年人按年龄从大到小排序 } } else { return a.order < b.order; // 非老年人按登记顺序排序 } } int main() { int n; cin >> n; for(int i =0 ;i<n;i++) { cin >> people[i].id >> people[i].age; people[i].order = i; // 记录登记顺序 } sort(people,people+n,cmp); for (int i = 0; i < n; i++) { cout << people[i].id << endl; } return 0; }
解题思路:
注意事项:
参考代码:
0.0分
49 人评分
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:533 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:946 |
震宇大神的杀毒软件 (C++代码)浏览:1117 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:759 |
【蟠桃记】 (C语言代码)浏览:664 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:619 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:937 |
WU-输出正反三角形 (C++代码)浏览:1021 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:635 |
C语言考试练习题_一元二次方程 (C语言代码)浏览:576 |