提交时间:2026-06-14 14:14:18

运行 ID: 91653

#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; // 存储每个人信息 struct Person { string name; int y, m, d; int idx; // 记录原始输入顺序下标 }; // 自定义比较函数 bool cmp(const Person& a, const Person& b) { // 生日不同:生日更早(年小/月小/日小)排前面 if (a.y != b.y) return a.y < b.y; if (a.m != b.m) return a.m < b.m; if (a.d != b.d) return a.d < b.d; // 生日相同:输入靠后(下标大)排前面 return a.idx > b.idx; } int main() { int n; cin >> n; vector<Person> people(n); for (int i = 0; i < n; ++i) { cin >> people[i].name >> people[i].y >> people[i].m >> people[i].d; people[i].idx = i; } sort(people.begin(), people.end(), cmp); // 输出姓名 for (auto& p : people) { cout << p.name << endl; } return 0; }