오늘의 목표
- 아침 코드카타
- 언리얼 마스터 라이브세션 3강 - 녹화본 복습
- 언리얼 마스터 라이브세션 7강? 수강
코드카타
[문제] K번째 수 정렬
나의 풀이
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
int i, j, k;
for (int it = 0; it < commands.size(); ++it)
{
i = commands[it][0];
j = commands[it][1];
k = commands[it][2];
vector<int> tempArr(array.begin() + i - 1 , array.begin() + j );
sort(tempArr.begin(), tempArr.end());
answer.push_back(tempArr[k - 1]);
}
return answer;
}
여기서 tempArr를 잘라낼때 sort (array.begin() + i - 1 , array.begin() + j)를 사용해야하는 이유
sort는 보통 마지막 원소 다음 위치를 받는다. vector의 end()같은 이터레이터를 반환해야 마지막 원소까지 포함시켜서 잘라낼 수 있다.
예를 들어 i가 2이고 j가 5일 때, 인덱스가 0에서 시작하는 걸 고려하여 i는 1, j는 5를 넣어줘야 인덱스 1~4까지의 숫자가 의도대로 포함된다.
언리얼 마스터 라이브세션


'Unreal5 공부 > TIL' 카테고리의 다른 글
| 2026/06/02 TIL (0) | 2026.06.02 |
|---|---|
| 2026/06/01 TIL (0) | 2026.06.01 |
| 2026/05/28 TIL (0) | 2026.05.28 |
| 2026/05/27 TIL (0) | 2026.05.27 |
| 2026/05/26 TIL (0) | 2026.05.26 |