Make Unreal REAL.
article thumbnail
Level 0. 콜라츠 수열 만들기

Level 0. 콜라츠 수열 만들기 #include #include using namespace std; vector solution(int n) { vector answer {n}; while (n != 1) answer.emplace_back(n += (n & 1) ? (2*n + 1) : -(n / 2)); return answer; }

article thumbnail
Level 0. 수열과 구간 쿼리 3

Level 0. 수열과 구간 쿼리 3 #include #include #include using namespace std; vector solution(vector arr, vector queries) { for (vector& query : queries) swap(arr[query[0]], arr[query[1]]); return arr; }

article thumbnail
Level 2. 다리를 지나는 트럭

Level 2. 다리를 지나는 트럭 처음에 다리를 정해진 순서로 건너간다는 말이 그냥 있는 말인 줄 알았는데, 정렬해 순서를 바꾸지 말고 입력을 그대로 쓰라는 말이었어서 조금 헷갈렸다. 만약, 크기 순으로 정렬하는 문제였다면 투 포인터로 풀 수 있었을 것이다. 다리 길이 크기의 큐를 만들고 현재 적재 중량을 관리해 다리에 추가할 수 있을 때는 무게를 추가하고, 불가능할 때는 0으로 채우면 된다. #include #include #include using namespace std; int solution(int bridge_length, int weight, vector truck_weights) { int answer = 0; int nTrucks = truck_weights.size(), nPassed..

article thumbnail
Level 0. 특별한 이차원 배열 2

Level 0. 특별한 이차원 배열 2 #include #include using namespace std; int solution(vector arr) { size_t n = arr.size(); for (int i = 0; i < n; ++i) for (int j = 0; j

article thumbnail
Level 0. 수 조작하기 2

Level 0. 수 조작하기 2 #include #include using namespace std; string solution(vector numLog) { size_t n = numLog.size() - 1; string answer(n, '\0'); const char* wasd = "d w s a"; for (int i = 0; i < n; ++i) answer[i] = wasd[numLog[i] - numLog[i + 1] + 10]; return answer; }

article thumbnail
Level 0. 가까운 1 찾기

Level 0. 가까운 1 찾기 #include #include #include using namespace std; int solution(vector arr, int idx) { auto result = find(next(arr.begin(), idx), arr.end(), 1); return (result == arr.end()) ? -1 : result - arr.begin(); }

검색 태그