cpp

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool cmp(const pair<ll, int> &a , const pair<ll, int> &b){
    if (a.second == b.second) return (a.first < b.first);
    return (a.second > b.second);   
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  ll n, num;
  map<ll, int> m;
  vector<pair<ll, int>> v;
  cin >> n;

  while(n--){
    cin >> num;
    m[num]++;  // 그 숫자 카운트 
  }
  
  copy(m.begin(), m.end(), back_inserter(v));
  // map을 사용하여 개수를 센 다음 vector에 삽입한다.
  // back_inserter() 반복자가 대입 동작을 push_back 삽입 동작으로 재정의하므로 복사되는 족족 리스트의 크기가 늘어난다.
  sort(v.begin(), v.end(), cmp);
  // 비교 함수를 사용해 정렬한다.
  cout << v[0].first;
}

 

참고 블로그 

sihyungyou.github.io/baekjoon-11652/

블로그 이미지

hjc_

୧( “̮ )୨

,