풀이
주어진 벡터의 일부분을 새로 정렬했을때 특정한 순서에 있는 숫자가 무엇인지 출력하는 문제이다.
일부분에 해당하는 범위를 새로운 벡터에 할당하고 정렬한다음에 특정한 순서에 있는 숫자를 answer에 담았다.
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
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;
temp.assign(array.begin() + commands[i][0]-1,array.begin()+commands[i][1]);
sort(temp.begin(),temp.end());
answer.push_back(temp[commands[i][2]-1]);
}
return answer;
}
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] H-Index c++ (0) | 2024.01.17 |
---|---|
[프로그래머스] 가장 큰 수 c++ (0) | 2024.01.16 |
[프로그래머스] 이중우선순위 c++ (0) | 2024.01.16 |
[프로그래머스] 디스크 컨트롤러 c++ (0) | 2024.01.14 |
[프로그래머스] 주식가격 c++ (1) | 2024.01.11 |