# 생각

array값을 수정해야 하므로

tmp배열을 추가로 선언하여 입력받은 범위만큼 sort함수를 사용해주면 된다

answer에는 tmp의 commands[i][2]번째 만큼이므로 인덱스에 주의해주자

 

 

# 전체 코드

#include <bits/stdc++.h>
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> tmp = array;
		sort(tmp.begin() + commands[i][0] - 1, tmp.begin() + commands[i][1]);
		answer.push_back(tmp[commands[i][0] + commands[i][2] - 2]);
	}

	return answer;
}

 


출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

'Algorithm > 프로그래머스' 카테고리의 다른 글

[Lv.2] 거리두기 확인하기  (0) 2022.05.07
[Lv.2] 가장 큰 수 with cpp  (0) 2022.03.05
[Lv.1] 모의고사 with cpp  (0) 2022.03.05
[Lv.3] 여행경로 with cpp  (0) 2022.03.05
[Lv.3] 단어 변환 with cpp  (0) 2022.03.04

+ Recent posts