본문 바로가기

분류 전체보기167

수 찾기 #1920 c++ 풀이 #include #include #include #include #include #include using namespace std; vector arr1; vector arr2; int main() { int N, M; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int temp; cin >> N; for (int i = 0; i > temp; arr1.push_back(temp); } cin >> M; for (int i = 0; i > temp; arr2.push_back(temp); } sort(arr1.begin(), arr1.end()); for (int i = .. 2023. 10. 5.
스택수열 #1874 c++ 풀이 #include #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; stack s; cin >> n; int temp; int topValue = 0; string answer; while (n--) { cin >> temp; if (temp > topValue) { while (temp > topValue) { s.push(++topValue); answer += '+'; } s.pop(); answer += '-'; } else { bool check = false; if (!s.empty()) { i.. 2023. 10. 5.
팩토리얼 0의 개수 #1676 c++ 풀이 https://www.acmicpc.net/problem/1676 1676번: 팩토리얼 0의 개수 N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오. www.acmicpc.net #include #include #include #include #include using namespace std; int count5(int k) { int n = k; int count = 0; while (1) { if (n > n; int k = n; int cnt5 = 0; .. 2023. 10. 5.
이진탐색 단순 순회 알고리즘으로, 풀수 없는 백준 문제가 생겨나서 이진탐색 알고리즘을 복습하게 되었습니다. (1654번) 이진탐색 이란? - 정렬된 배열에서 검색 범위를 줄여 나가면서 검색 값을 찾는 알고리즘. 시간 복잡도 - O(logN) 정렬된 배열의 중간값을 임의로 선택하여 찾고자 하는 키(key) 값과 비교하는 탐색 알고리즘. 중앙값을 기준으로 왼쪽 오른쪽 탐색을 달리한다. 반복, 재귀, STL 이용하여 구현가능 //반복문을 이용한 이진탐색을 이용하여 탐색 bool BinarySearch(int *arr, int len, int key){ int start = 0; int end = len-1; int mid; while(end - start >= 0) { mid = (start + end) / 2; //.. 2023. 10. 4.