본문 바로가기

problem solving

[프로그래머스]K번째수

그저  지문을 따라서 풀면 되는 아주 쉬운 문제.

#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    vector<int> temp;
    for(int i = 0; i < commands.size(); i++) {
        temp.clear();
        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

'problem solving' 카테고리의 다른 글

[프로그래머스]2016년  (0) 2020.03.06
[프로그래머스]체육복  (0) 2020.03.06
[프로그래머스]모의고사  (0) 2020.03.06
[프로그래머스]완주하지 못한 선수  (0) 2020.03.06
[프로그래머스]124나라의 숫자  (0) 2020.03.06