提交时间:2024-04-16 16:39:01

运行 ID: 143546

#include<bits/stdc++.h> 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; }