개발자 '쑥말고인절미'

[프로그래머스] C++ Level1 K번째수 본문

STUDY/코딩테스트

[프로그래머스] C++ Level1 K번째수

쑥말고인절미 2022. 8. 8. 21:43

문제


내 답안

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer, empty;
    int start, end, search;

    for(int i=0; i < commands.size(); i++){
        start = commands[i][0];
        end = commands[i][1];
        search = commands[i][2];
        
        for(int j = start-1; j <= end-1; j++){
            empty.push_back(array[j]);
        }

        sort(empty.begin(), empty.end(), less<int>());
        
        answer.push_back(empty[search-1]);

        cout<<endl;
        vector<int>().swap(empty);
    }
    
    return answer;
}