提交时间:2026-04-14 16:41:49
运行 ID: 436402
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; // 排序规则:先按长度短→长,长度相同按字典序 bool cmp(const string &a, const string &b) { if (a.size() != b.size()) return a.size() < b.size(); return a < b; } int main() { int n; cin >> n; // key: 月 日, value: 这一天的所有名字 map<pair<int, int>, vector<string>> group; // 输入 for (int i = 0; i < n; i++) { string name; int m, d; cin >> name >> m >> d; group[{m, d}].push_back(name); } bool has = false; // 遍历(map自动按日期从小到大) for (auto &entry : group) { int m = entry.first.first; int d = entry.first.second; auto &names = entry.second; // 只有 >=2 人才输出 if (names.size() >= 2) { has = true; // 排序名字 sort(names.begin(), names.end(), cmp); // 输出 cout << m << " " << d << " "; for (int i = 0; i < names.size(); i++) { if (i > 0) cout << " "; cout << names[i]; } cout << endl; } } // 没有相同生日 if (!has) { cout << "None" << endl; } return 0; }