提交时间:2023-09-13 13:50:15

运行 ID: 102485

# include <iostream> # include <algorithm> #include <map> using namespace std ; struct name { string xing , ming ; int n ; } ; name a [114514] ; map <string , int> f ; bool cmp ( name x , name y ) { if ( f [x . xing] != f [y . xing] ) { return ( f [x . xing] > f [y . xing] ) ; } return x . n < y . n ; } int main ( ) { string x , m ; int cnt = 0 ; while ( cin >> x >> m ) { cnt ++ ; a [cnt] . xing = x ; a [cnt] . ming = m ; a [cnt] . n = cnt ; f [x] ++ ; } stable_sort ( a + 1 , a + cnt + 1 , cmp ) ; for ( int i = 1 ; i <= cnt ; i ++ ) { cout << a [i] . xing << ' ' << a [i] . ming << endl ; } return 0 ; }