[AlgorithmCodeKata] 2026-03-23 | 명예의 전당 (1)

2026. 3. 23. 21:58·AlgorithmCodekata

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
'AlgorithmCodekata' 카테고리의 다른 글
  • [AlgorithmCodeKata] 2026-05-06 | 햄버거 만들기
  • [AlgorithmCodeKata] 2026-03-25 | 카드 뭉치
  • [AlgorithmCodeKata] 2026-03-20 | 콜라 문제
  • [AlgorithmCodeKata] 2026-03-18 | 문자열 내 마음대로 정렬하기
개발근육체육관원
개발근육체육관원
개발 근육 단련 체육관 입니다.
  • 개발근육체육관원
    개발근육체육관
    개발근육체육관원
  • 전체
    오늘
    어제
    • 분류 전체보기 (19) N
      • 언리얼 게임개발 (9) N
      • AlgorithmCodekata (9)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    AlgorithmCodekata
    Til
    c++
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
개발근육체육관원
[AlgorithmCodeKata] 2026-03-23 | 명예의 전당 (1)
상단으로

티스토리툴바