#include <map>
선언 - map<int, int> m;
중복된걸 제외시켜주고 중복된 것들중 숫자세는 곳에서 사용
for (int i = 0; i < n; i++) {
long long key;
cin >> key;
m[key]++;
}
map에 담긴 요소들 출력하는 방법
map<long long, long long>::iterator iter;
for (iter = m.begin(); iter != m.end(); iter++) {
if (ans < iter->second) {
ans = iter->second;
key = iter->first;
}
}
iter를 이용하여 map의 처음부터 끝까지 탐색한다.
'Algorithm > 코테정리' 카테고리의 다른 글
| [코테정리] C++ 소수점 N자리 출력하기 (0) | 2021.09.09 |
|---|---|
| [코테정리] C++ 순열, 조합구현(재귀) (0) | 2021.06.07 |
| [코테정리] C++ vector 기법 (0) | 2021.06.07 |
| [코테정리] C++ 윤년, 윤달, 요일 출력하기 (0) | 2021.06.07 |
| [코테정리] C++ N자리 2진수 만들기 및 2진수 변환 (0) | 2021.06.07 |
