K번째 수

magicdrill·2024년 12월 26일
0

K번째 수

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

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    int a, b;
    int i, j, k;
    
    for(a = 0; a < commands.size(); a++){
        cout << a << "회차 순회\n";
        i = commands[a][0];
        j = commands[a][1];
        k = commands[a][2];
        cout << "i : " << i << "/ j : " << j << "/ k : " << k << "\n";
        
        vector<int> temp;//임시 벡터 생성
        for(b = i; b <= j; b++){
            temp.push_back(array[b - 1]);
        }
        sort(temp.begin(), temp.end());//정렬
        cout << "추출 후 정렬한 임시 벡터 : ";
        for(int t : temp){
            cout << t << " ";
        }
        cout << "\n\n";
        answer.push_back(temp[k - 1]);
    }
    
    return answer;
}

0개의 댓글