개발일지/코딩테스트
[Programmers] 명예의 전당(1) (c++)
쫌눈
2025. 4. 8. 12:36
728x90
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/138477
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(int k, vector<int> score) {
vector<int> answer;
vector<int> top;
for (int i = 0; i < score.size(); i++)
{
if (top.size() > 0)
{
if (top.size() < k)
{
top.emplace_back(score[i]);
}
else {
sort(top.begin(), top.end());
if (top[0] < score[i])
{
top.erase(top.begin(), top.begin()+1);
top.emplace_back(score[i]);
}
sort(top.begin(), top.end());
}
}
else {
top.emplace_back(score[i]);
}
sort(top.begin(), top.end());
answer.emplace_back(top[0]);
}
return answer;
}
728x90
반응형