작심 24/7

[백준] 11652번 카드 본문

백준

[백준] 11652번 카드

모닝수박 2020. 8. 27. 12:25
 

11652번: 카드

준규는 숫자 카드 N장을 가지고 있다. 숫자 카드에는 정수가 하나 적혀있는데, 적혀있는 수는 -262보다 크거나 같고, 262보다 작거나 같다. 준규가 가지고 있는 카드가 주어졌을 때, 가장 많이 가지

www.acmicpc.net

map을 이용하여 숫자 카드의 개수를 세고

copy 함수를 이용해 map을 vector에 복사해준 뒤

카드의 개수를 기준으로 내림차순, 카드 숫자를 기준으로 오름차순

정렬한 결과 맨 첫 번째 값을 출력해준다.

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int N;
long long a;
map <long long, int> m;
vector < pair<long long, int> > v;

bool compare(pair<long long, int>  a, pair<long long, int> b) {
	if (a.second == b.second) return a.first < b.first;
	else return a.second > b.second;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		m[a]++;
	}

	copy(m.begin(), m.end(), back_inserter(v));
	sort(v.begin(), v.end(), compare);

	cout << v[0].first;

	return 0;
}

'백준' 카테고리의 다른 글

[백준] 1339번 단어 수학  (0) 2020.08.28
[백준] 16500번 문자열 판별  (0) 2020.08.27
[백준] 9252번 LCS 2  (0) 2020.08.27
[백준] 5582번 공통 부분 문자열  (0) 2020.08.25
[백준] 7579번 앱  (0) 2020.08.25
Comments