Coding
-
[프로그래머스] 두 큐 합 같게 만들기 c++Coding Test/programmers 2022. 9. 5. 15:00
문제 설명 같은 크기의 vector가 두개 주어지고, 두 벡터의 원소들의 합/2 == 벡터1, 벡터2 각 원소들의 합과 같도록 원소를 이동시켜야한다. 벡터1의 원소들의 합과 벡터2의 원소들의 합이 같은지 확인하면 된다. (문제는 queue라고 하는데 인자는 vector 형으로 주어진다.) 한 번의 pop과 한 번의 insert 작업은 1회 수행한 것으로 간주한다. 제한 사항 1 ≤ queue1의 길이 = queue2의 길이 ≤ 300,000 1 ≤ queue1의 원소, queue2의 원소 ≤ 109 주의: 언어에 따라 합 계산 과정 중 산술 오버플로우 발생 가능성이 있으므로 long type 고려가 필요합니다. 입출력 예 queue1 queue2 result [3, 2, 7, 2] [4, 6, 5, 1]..
-
[c++] unique 함수Programming/c++ 2022. 8. 1. 22:47
unique 함수 : 지정된 범위에서 서로 옆에 있는 중복 요소를 제거합니다. 1.함수 헤더 파일 #include 2.함수 원형 template ForwardIterator unique( ForwardIterator first, ForwardIterator last); template ForwardIterator unique( ForwardIterator first, ForwardIterator last, BinaryPredicate pred); template ForwardIterator unique( ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last); template ForwardIterator unique( ExecutionP..
-
[프로그래머스] 같은 숫자는 싫어 c++Coding Test/programmers 2022. 8. 1. 16:35
문제 설명 배열 arr가 주어집니다. 배열 arr의 각 원소는 숫자 0부터 9까지로 이루어져 있습니다. 이때, 배열 arr에서 연속적으로 나타나는 숫자는 하나만 남기고 전부 제거하려고 합니다. 단, 제거된 후 남은 수들을 반환할 때는 배열 arr의 원소들의 순서를 유지해야 합니다. 예를 들면, arr = [1, 1, 3, 3, 0, 1, 1] 이면 [1, 3, 0, 1] 을 return 합니다. arr = [4, 4, 4, 3, 3] 이면 [4, 3] 을 return 합니다. 배열 arr에서 연속적으로 나타나는 숫자는 제거하고 남은 수들을 return 하는 solution 함수를 완성해 주세요. 제한 사항 배열 arr의 크기 : 1,000,000 이하의 자연수 배열 arr의 원소의 크기 : 0보다 크거나..
-
[프로그래머스] 폰켓몬 c++Coding Test/programmers 2022. 8. 1. 16:20
문제 설명 제한 사항 nums는 폰켓몬의 종류 번호가 담긴 1차원 배열입니다. nums의 길이(N)는 1 이상 10,000 이하의 자연수이며, 항상 짝수로 주어집니다. 폰켓몬의 종류 번호는 1 이상 200,000 이하의 자연수로 나타냅니다. 가장 많은 종류의 폰켓몬을 선택하는 방법이 여러 가지인 경우에도, 선택할 수 있는 폰켓몬 종류 개수의 최댓값 하나만 return 하면 됩니다. 입출력 예 nums result [3,1,2,3] 2 [3,3,3,2,2,4] 3 [3,3,3,2,2,2] 2 문제 풀이 N마리의 폰켓몬 중 N/2를 가질 수 있다. 중복을 허용하지 않는 map을 사용해서 폰켓몬의 종류를 카운트한다. map의 크기가 폰켓몬 종류 개수가 된다. #include #include using name..
-
[HackerRank] Tower Breakers c++Coding Test/HackerRank 2022. 7. 20. 19:20
Problem Two players are playing a game of Tower Breakers! Player 1 always moves first, and both players always play optimally.The rules of the game are as follows: Initially there are n towers. Each tower is of height m. The players move in alternating turns. In each turn, a player can choose a tower of height x and reduce its height to y, where 1
-
[HackerRank] Zig Zag Sequence C++Coding Test/HackerRank 2022. 7. 20. 14:54
Problem In this challenge, the task is to debug the existing code to successfully execute all provided test files. Given an array of N distinct integers, transform the array into a zig zag sequence by permuting the array elements. A sequence will be called a zig zag sequence if the first K elements in the sequence are in increasing order and the last K elements are in decreasing order, where k =..