C++:: 프로그래머스 <K번째수>

jahlee·2023년 4월 11일
0

프로그래머스_Lv.1

목록 보기
16/75
post-thumbnail

간단한 정렬 문제이다.

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

vector<int> solution(vector<int> array, vector<vector<int>> commands)
{
    vector<int> answer;
    int n = commands.size();
    for (int i=0;i<n;i++)
    {
        vector<int> v;
        for(int j=commands[i][0]-1;j<commands[i][1];j++)
            v.push_back(array[j]);//해당 범위 수를 새 벡터에 넣어준다.
        sort(v.begin(), v.end());//오름차순 정렬
        answer.push_back(v[commands[i][2]-1]);//원하는 인덱스 수 넣어준다.
    }
    return answer;
}

0개의 댓글