프로그래머스 138477 명예의 전당 (1)

Jmnote (토론 | 기여)님의 2023년 11월 27일 (월) 20:19 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

프로그래머스 138477 명예의 전당 (1)

2 C++

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> solution(int k, vector<int> score) {
    vector<int> answer;
    vector<int> ranked;
    for(auto &s: score) {
        ranked.push_back(s);
        sort(ranked.begin(), ranked.end(), greater<int>());
        if(ranked.size()>k) ranked.pop_back();
        answer.push_back(ranked.back());
    }
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}