https://school.programmers.co.kr/learn/courses/30/lessons/138476?language=cpp
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int solution(int k, vector<int> tangerine) {
int answer = 0;
map<int, int> m;
// map에 개수만큼 저장
for_each(tangerine.begin(), tangerine.end(), [&](const auto& el)
{
m[el]++;
});
using pp = pair<int, int>;
vector<pp> vec(m.begin(), m.end());
sort(vec.begin(), vec.end(), [](const pp& a, const pp& b) // 내림차순 정렬
{
if (a.second == b.second) return a.first < b.first;
return a.second > b.second;
});
for (const auto& num : vec) // 개수가 없으면 정답
{
answer++;
if (k > num.second) k -= num.second;
else break;
}
return answer;
}
GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드
백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.
github.com
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (정렬) Lv 2. H-Index (0) | 2023.06.11 |
---|---|
[Programmers] (월간 코드 챌린지 시즌2) Lv 2. 괄호 회전하기 (0) | 2023.06.10 |
[Programmers] Lv 2. 멀리 뛰기 (0) | 2023.06.02 |
[Programmers] Lv 2. N개의 최소공배수 (0) | 2023.06.01 |
[Programmers] (Summer/Winter Coding(~2018)) Lv 2. 점프와 순간 이동 (0) | 2023.05.31 |
댓글