提交时间:2023-09-13 13:24:16

运行 ID: 102343

#include<bits/stdc++.h> using namespace std; int n=1; struct node{ string x,y; int pos; }a[50001]; map<string,int> mp; bool cmp(node x,node y){ if(mp[x.x]==mp[y.x]) return x.pos<y.pos; return mp[x.x]>mp[y.x]; } signed main(){ while(cin>>a[n].x>>a[n].y){ mp[a[n].x]++; a[n].pos=n; n++; } n--; sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++){ cout<<a[i].x<<" "<<a[i].y<<endl; } return 0; }