Run ID:157479

提交时间:2026-07-24 12:50:39

#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; // 定义存储朋友信息的结构体 struct FriendInfo { string name; // 姓名 string birth; // 生日 yyyymmdd string phone; // 手机号 }; // 自定义排序比较函数 bool cmp(const FriendInfo &a, const FriendInfo &b) { // 1. 生日越小,年龄越大,排在前面 if (a.birth != b.birth) { return a.birth < b.birth; } // 2. 生日相同,姓名字典序升序 if (a.name != b.name) { return a.name < b.name; } // 3. 姓名相同,电话号码升序 return a.phone < b.phone; } int main() { int n; cin >> n; vector<FriendInfo> list; // 读取n条信息 for (int i = 0; i < n; ++i) { FriendInfo f; cin >> f.name >> f.birth >> f.phone; list.push_back(f); } // 排序 sort(list.begin(), list.end(), cmp); // 输出结果 for (auto &item : list) { cout << item.name << " " << item.birth << " " << item.phone << endl; } return 0; }