본문 바로가기
프로그래머스

[42748] K번째수

by Jcoder 2018. 9. 17.


#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands)
{
vector<int> answer;
int i, j, k;
int size = commands.size();
for (int s = 0; s < size; s++)
{
vector<int> choice;
i = commands[s][0];
j = commands[s][1];
k = commands[s][2];
int ii = i - 1;
for (int a = 0; a <= j - i; a++)
{
choice.push_back(array[ii]);
ii++;
}
sort(choice.begin(), choice.end());
int b = choice[k - 1];
answer.push_back(b);
}
return answer;
}


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

[14406] 소수의 합  (0) 2018.10.28
[42840] 모의고사  (0) 2018.10.21
[42588] 탑  (0) 2018.10.20
[42862] 체육복  (0) 2018.10.20
[42583] 주식가격  (0) 2018.09.14