https://school.programmers.co.kr/learn/courses/30/lessons/138477
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
1. 의사 코드
for문에서 k 까지는 cnadidate에서 가장 작은값을 answer에 추가
이후 부터 가장 작은값과 비교하여 클 경우 가장 작은 값을 교체
sort로 정렬 후 가장 작은 값을 answer에 추가
2. 제출 코드
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(int k, vector<int> score) {
vector<int> answer;
vector<int> candidate;
for(int i = 0; i < score.size(); ++i)
{
if(i < k)
{
candidate.push_back(score[i]);
sort(candidate.begin(),candidate.end());
}
else
{
if(score[i] > candidate[0])
{
candidate[0] = score[i];
sort(candidate.begin(),candidate.end());
}
}
answer.push_back(candidate[0]);
}
return answer;
}
3. Trouble Shooting
반응형
'AlgorithmCodekata' 카테고리의 다른 글
| [AlgorithmCodeKata] 2026-05-06 | 햄버거 만들기 (3) | 2026.05.06 |
|---|---|
| [AlgorithmCodeKata] 2026-03-25 | 카드 뭉치 (0) | 2026.03.25 |
| [AlgorithmCodeKata] 2026-03-20 | 콜라 문제 (0) | 2026.03.20 |
| [AlgorithmCodeKata] 2026-03-18 | 문자열 내 마음대로 정렬하기 (0) | 2026.03.18 |
| [AlgorithmCodeKata] 2026-03-12 | 문자열 내 마음대로 정렬하기 (0) | 2026.03.12 |