You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
# include <unordered_map>
using namespace std ;
//自定义排序函数
bool SortByValueKey ( const pair < int , int > & v1 , const pair < int , int > & v2 ) //注意: 本函数的参数的类型一定要与vector中元素的类型一致
{
if ( v1 . second = = v2 . second ) return v1 . first < v2 . first ;
return v1 . second > v2 . second ;
}
int main ( ) {
//录入数据到vector数组
int n ;
cin > > n ;
unordered_map < int , int > myMap ;
for ( int i = 0 ; i < n ; i + + ) {
int c ;
cin > > c ;
myMap [ c ] + + ;
}
//保存到数组中
vector < pair < int , int > > vec ;
for ( auto iter = myMap . begin ( ) ; iter ! = myMap . end ( ) ; + + iter ) {
vec . push_back ( make_pair ( iter - > first , iter - > second ) ) ;
}
//开始自定义排序
sort ( vec . begin ( ) , vec . end ( ) , SortByValueKey ) ;
//输出结果
for ( auto c : vec ) {
cout < < c . first < < " " < < c . second < < endl ;
}
return 0 ;
}