●문제

●입출력

사용알고리즘 : sort
문제해석 : array배열의 2차원배열의 command[0]번부터 command[1]까지 자른뒤
정렬한뒤 command[3]배열값을 return하여 완성하면 return값 도출
풀이
#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;
}
점수 : 1
레벨 : 1
'C++ 프로그래머스 > Sort' 카테고리의 다른 글
| 프로그래머스(C++) - H-Index (1) | 2025.08.19 |
|---|---|
| 프로그래머스(C++) - 가장 큰 수 (0) | 2025.08.18 |
| Algorithm - Sorting (0) | 2025.08.13 |
| 프로그래머스(C++) - 명예의 전당(1) (0) | 2025.07.27 |
