E. 【例题5】生日相同
解析
字符串操作,本题解采取了多关键词排序
Code
#include <bits/stdc++.h> using namespace std; int f, n; struct node { int y, r; string s; }a[100005]; int cmp (node x, node y) { if (x.y != y.y) return x.y < y.y; if (x.r != y.r) return x.r < y.r; if (x.s.length () != y.s.length ()) return x.s.length () < y.s.length (); return x.s < y.s; } int main () { cin >> n; for (int i = 1; i <= n; ++ i) cin >> a[i].s >> a[i].y >> a[i].r; sort (a + 1, a + 1 + n, cmp); for (int i = 1; i <= n; ++ i) { if (a[i].y == a[i + 1].y && a[i].r == a[i + 1].r) { cout << a[i].y << ' ' << a[i].r << ' ' << a[i].s << ' '; f = true; while (a[i].y == a[i + 1].y && a[i].r == a[i + 1].r) { i ++; cout << a[i].s << ' '; } cout << endl; } } if (!f) cout << "None" << endl; return 0; }