Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- lis
- dfs
- Knapsack
- MST
- 우선순위 큐
- 조합
- 빠른 입출력
- 백트래킹
- 중복 순열
- 완전 탐색
- BFS
- 큐
- 피보나치 수
- 재귀
- 순열
- 문자열
- 메모리풀
- 비트마스크
- 링크드리스트
- 이분 탐색
- 크루스칼
- 스택
- 세그먼트 트리
- DP
- 그리디
- BeautifulSoup
- SSAFY
- 시뮬레이션
- 클래스
- 분할 정복
Archives
- Today
- Total
작심 24/7
[백준] 11652번 카드 본문
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