본문 바로가기

전체 글

(199)
[프로그래머스] 정렬 / k번째 수 #include #include #include using namespace std; vector solution(vector array, vector commands) { vector answer; for(vector elem : commands) { vector temp; temp.assign(array.begin() + elem[0] - 1, array.begin() + elem[1]); sort(temp.begin(), temp.end()); answer.push_back(temp[elem[2]-1]); } return answer; }
[프로그래머스] 해싱 / 위장 문제 설명 스파이들은 매일 다른 옷을 조합하여 입어 자신을 위장합니다. 예를 들어 스파이가 가진 옷이 아래와 같고 오늘 스파이가 동그란 안경, 긴 코트, 파란색 티셔츠를 입었다면 다음날은 청바지를 추가로 입거나 동그란 안경 대신 검정 선글라스를 착용하거나 해야 합니다. 종류이름 얼굴 동그란 안경, 검정 선글라스 상의 파란색 티셔츠 하의 청바지 겉옷 긴 코트 스파이가 가진 의상들이 담긴 2차원 배열 clothes가 주어질 때 서로 다른 옷의 조합의 수를 return 하도록 solution 함수를 작성해주세요. 제한사항 clothes의 각 행은 [의상의 이름, 의상의 종류]로 이루어져 있습니다. 스파이가 가진 의상의 수는 1개 이상 30개 이하입니다. 같은 이름을 가진 의상은 존재하지 않습니다. clothe..
[백준 2750번] 수 정렬하기 / C++ #include #include #include using namespace std; int main() { int *arr; int num; cin >> num; arr = new int[num]; for (int i = 0; i > arr[i]; sort(arr, arr + num); cout
[C++] 재귀호출로 회문 판별하기 #include #include #include using namespace std; int palindrome(string arr,int start,int end) { if (start >= end) return 0; else if (arr[start] == arr[end]) return palindrome(arr, start + 1, end - 1); else return 1; } int main() { string arr; arr = "level"; int res; res = palindrome(arr, 0, arr.size() - 1); cout
[C++] 재귀호출로 배열의 합 구하기 #include #include using namespace std; int add(int arr[], int index) { if (index == 0) return arr[index]; else return arr[index] + add(arr, index - 1); } int main() { int arr[10], res; for (int i = 0; i < 10; i++) { arr[i] = rand() % 100; } res = add(arr, 9); cout
[C++] 재귀호출로 팩토리얼 구하기 #include #include using namespace std; int fact(int num) { if (num
[C++] 삽입정렬 코드 구현 #include #include using namespace std; int *insertion_sort(int data[], int size) { for (int i = 1; i = 1; j--) { if (data[j - 1] > data[j]) swap(data[j - 1], data[j]); else break; } } return data; } int main() { int arr[10] = {5, 2, 7, 10, 9, 1, 3, 6, 8, 4 }; int *result; result = insertion_sort(arr, sizeof(arr)/sizeof(int)); for (int i = 0; i < 10; i++) cout
[C++] 선택정렬 코드 구현 #include #include using namespace std; int *selection_sort(int data[], int size) { int min; for (int i = 0; i < size; i++) { min = i; for (int j = i; j < size; j++) { if (data[j] < data[min]) min = j; } swap(data[i], data[min]); } return data; } int main() { int arr[10] = {5, 2, 7, 10, 9, 1, 3, 6, 8, 4 }; int *result; result = selection_sort(arr, sizeof(arr)/sizeof(int)); for (int i = 0; i < 10;..