본문 바로가기
Computer Science/Coding Test

c++(cpp) 프로그래머스 - 코딩테스트 : k번째 수

by hzyiunn 2023. 1. 23.
728x90
반응형

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

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    for(int i = 0 ; i < commands.size() ; i++)
    {
        vector<int> temp;
        for(int j = commands[i][0]-1 ; j < commands[i][1]; j ++)
        {
            temp.push_back(array[j]);
        }
        sort(temp.begin(), temp.end());
        answer.push_back(temp[commands[i][2]-1]);
    }
    
    return answer;
}
728x90
반응형

댓글