Skip to content

Commit

Permalink
정렬_K번째수 코드 업로드
Browse files Browse the repository at this point in the history
프로그래머스 코딩테스트 연습

문제 코드 업로드
  • Loading branch information
witheunjin committed Mar 10, 2020
1 parent 710966c commit b7e5561
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Programmers/정렬/Sorting_KthNumber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//Á¤·Ä_K¹ø° ¼ö
//URL: https://programmers.co.kr/learn/courses/30/lessons/42748

#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
int siz = commands.size();
for (int i = 0; i < siz; ++i) {
int start = commands[i][0];
int end = commands[i][1];
int k = commands[i][2];
vector<int> temp;
temp.clear();
for (int j = start - 1; j < end; ++j) {
temp.push_back(array.at(j));
}
int size = temp.size();
sort(temp.begin(), temp.begin()+size);
answer.push_back(temp.at(k-1));
}
return answer;
}

/*
int main() {
vector<int> arr = { 1,5,2,6,3,7,4 };
vector<vector<int>> com = { {2,5,3},{4,4,1},{ 1,7,3 } };
vector<int> a = solution(arr, com);
int size = a.size();
for (int i = 0; i < size; ++i) {
cout << a.at(i) << " ";
}
}
*/

0 comments on commit b7e5561

Please sign in to comment.