1.
#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;
}
|
cs |
2.
#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++)
{
int num[100];
int numIdx = 0;
for(int j = commands[i][0]; j <= commands[i][1]; j++)
{
num[numIdx] = array[j-1];
numIdx++;
}
sort(num, num+numIdx);
answer.push_back(num[commands[i][2]-1]);
}
return answer;
}
|
cs |
'Programmers > Level 1' 카테고리의 다른 글
[프로그래머스 1] 가운데 글자 가져오기 (C/C++) (0) | 2019.10.17 |
---|---|
[프로그래머스 1] 2016년 (C/C++) (0) | 2019.10.17 |
[프로그래머스 1] 체육복 (C/C++) (0) | 2019.10.16 |
[프로그래머스 1] 모의고사 (C/C++) (0) | 2019.10.16 |
[프로그래머스 1] 완주하지 못한 선수 (C/C++) (0) | 2019.10.16 |