提交时间:2023-09-11 22:16:51

运行 ID: 101966

#include <iostream> #include <algorithm> #include <map> using namespace std; typedef long long LL; struct node { string x, m; int id, c; } p[50010]; int n; map<string, int> f; bool cmp(node a, node b) { if (a.c != b.c) return a.c > b.c; return a.id < b.id; } int main() { for (n = 1; cin >> p[n].x >> p[n].m; n++) { f[p[n].x]++; p[n].id = n; } n--; for (int i = 1; i <= n; i++) p[i].c = f[p[i].x]; sort(p + 1, p + n + 1, cmp); for (int i = 1; i <= n; i++) cout << p[i].x << " " << p[i].m << endl; return 0; }