Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
436404 顾鑫辰 【C5-9】病人排队 C++ 通过 100 10 MS 256 KB 998 2026-04-14 16:43:07

Tests(10/10):


#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Patient { string id; int age; int order; // 登记顺序 }; // 排序规则 bool cmp(const Patient &a, const Patient &b) { bool a_old = (a.age >= 60); bool b_old = (b.age >= 60); // 一个老人一个不是,老人优先 if (a_old != b_old) { return a_old; } // 都是老人 if (a_old && b_old) { if (a.age != b.age) return a.age > b.age; // 年龄大在前 else return a.order < b.order; // 登记早在前 } // 都不是老人,按登记顺序 return a.order < b.order; } int main() { int n; cin >> n; vector<Patient> p(n); for (int i = 0; i < n; ++i) { cin >> p[i].id >> p[i].age; p[i].order = i; } sort(p.begin(), p.end(), cmp); for (auto &x : p) { cout << x.id << endl; } return 0; }


测评信息: