분류 전체보기
-
[Codility] GenomicRangeQuery c++Coding Test/codility 2022. 8. 11. 15:00
문제 DNA서열은 A, C, G, T 로 구성 되어 있고 1, 2, 3, 4 로 표현된다. string으로 DNA 서열이 주어진다. 배열 P ,Q 의 K번째 값으로 string s의 K(P) ~ K(Q)번째 원소들 중 서열이 제일 먼저인 DNA 인덱스를 저장한다. 문제 해결 2중 for문을 사용하면 시간 복잡도 테스트를 통과하지 못해서 2중 for문을 사용하지 않게 코드를 짜보았다. // you can use includes, for example: #include vector solution(string &S, vector &P, vector &Q) { vector result; for (int i = 0; i < P.size(); i++) { int index = Q[i] - P[i]; string ..
-
[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 =..