지우너
[프로그래머스] k번째수 C++ 본문
문제
https://school.programmers.co.kr/learn/courses/30/lessons/42748
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
풀이 및 코드
vector에도 substring이 있을 거 같은데, 몰라서 그냥 for문을 돌면서 직접 넣어줬다.
#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 start = commands[i][0]-1; // 0-based
int end = commands[i][1]-1;
int idx = commands[i][2]-1;
vector<int> tmp;
for(int j=start; j<=end; j++){
tmp.push_back(array[j]);
}
sort(tmp.begin(), tmp.end());
answer.push_back(tmp[idx]);
}
return answer;
}
'Problem Solving' 카테고리의 다른 글
[프로그래머스] 전력망을 둘로 나누기 C++ (0) | 2025.03.10 |
---|---|
[프로그래머스] 피로도 C++ (0) | 2025.03.09 |
[프로그래머스] 카펫 C++ (0) | 2025.02.21 |
[프로그래머스] 모의고사 C++ (0) | 2025.02.19 |
[프로그래머스] 최소 직사각형 (0) | 2025.02.19 |