![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fb0y5S0%2FbtqJXWUAism%2Fai1MEuwLcVYjppO8C7SFI1%2Fimg.png)
[알고리즘 문제] 43. 뮤직비디오(이분검색 응용)
2020. 10. 2. 20:48
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int count(const vector& vInt, const int size) { int i, cnt = 1, sum = 0; for (i = 0; i size) { cnt++; sum = vInt[i]; } else { sum += vInt[i]; } } return cnt; } int main(void) { int n, m, i, left = 1, right = 0, mid, res, max = -2147000000; cin >> n >> m; vector vInt(n); for (i = 0; i > v..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FOa02Z%2FbtqJ0pBDV6x%2FMAuFhLRgd8gIPcEqcoQiRk%2Fimg.png)
[알고리즘 문제] 42. 이분검색
2020. 10. 2. 04:47
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, m, i, left, right, center, result = -1; cin >> n >> m; vector vInt(n); for (i = 0; i > vInt[i]; sort(vInt.begin(), vInt.end()); left = 0; right = n - 1; while (left
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FdC0uYP%2FbtqJ3ihIDcH%2FMAriKcY8Pqv8xAzEO0zK50%2Fimg.png)
[알고리즘 문제] 41. 연속된 자연수의 합
2020. 10. 2. 04:32
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i, j, sum, num, cnt, cnt2 = 0; bool flag; cin >> n; i = n / 2; if (n % 2 != 0) i += 1; for (; i >= 0; --i) { sum = 0; cnt = 0; num = i; flag = false; while (true) { sum += num; if (sum == n) { flag = true; ++cnt2; break; } else if (sum > n) break; --num; ++cnt; } if (flag) { for (j = cnt; j > 0; --j) cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcZrLAF%2FbtqJU4d1VCt%2F4nKG0JbRKtokkx9yRY7Y80%2Fimg.png)
[알고리즘 문제] 40. 교집합(투포인트 알고리즘)
2020. 9. 29. 22:38
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, m, i, p1 = 0, p2 = 0, p3 = 0; cin >> n; vector vN(n); for (i = 0; i > vN[i]; sort(vN.begin(), vN.end()); cin >> m; vector vM(m); for (i = 0; i > vM[i]; sort(vM.begin(), vM.end()); vector vResult(n+m); while (p1 vM[p2]) ++p2; else {..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FNTmvy%2FbtqJVphVxMS%2FK4wGxSzIMXurw8QgruZsvK%2Fimg.png)
[알고리즘 문제] 39. 두 배열 합치기
2020. 9. 29. 22:08
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, m, i, j; cin >> n; vector vN(n); for (i = 0; i > vN[i]; cin >> m; vector vM(m); vector vAnswer; vAnswer.resize(n + m); for (i = 0; i > vM[i]; i = j = 0; while (true) { if (vN[i] > vM[j]) { vAnswer[i + j] = vM[j]; ++j; } else if (vN[i] < vM[j]) { vAnswer[i + j] = vN[i]; ++i; } else { // 같은 경우 ..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbad3qw%2FbtqJUNpZMaA%2FSuLcnot4RLHEfku2lS8aLK%2Fimg.png)
[알고리즘 문제] 38. Inversion Sequence
2020. 9. 29. 21:01
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i, j, temp; cin >> n; vector is(n); vector os(n); for (i = 0; i > is[i]; os[n - 1] = n; for (i = n - 2; i >= 0; --i) { temp = i + 1; for (j = 0; j < is[i]; ++j) { os[i + j] = os[i + j + 1]; } os[i + j] = temp; } for (i = 0; i < n; ++i) cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcZJsxC%2FbtqJPB9CVhi%2FmsKmqeTL9ZHe38XOEo0zl0%2Fimg.png)
[알고리즘 문제] 37. Least Recently Used(카카오 캐시 문제 변형)
2020. 9. 28. 13:48
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int s, n, i, j, temp, idx; cin >> s; cin >> n; vector vSize(s); vector vNumber(n); for (i = 0; i > vNumber[i]; idx = 0; temp = 0; for (j = 0; j < s; ++j) { if (vNumber[i] != vSize[j]) continue; idx = j; temp = vSize[j]; break; } // 현재 vSize에 있는지 체크, 해당 인덱스 가지고 있어야 함 if(idx != 0) { // 맨앞으로 꺼내오기 for (j = idx - 1; ..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fb8JDYo%2FbtqJF0bYpiu%2FrOabaGgpXKjoT9mlg4EqDK%2Fimg.png)
[알고리즘 문제] 36. 삽입정렬
2020. 9. 28. 13:32
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i, j, temp; cin >> n; vector vInt(n); for (i = 0; i > vInt[i]; for (i = 1; i = 0; --j) { if (vInt[j] > temp) { vInt[j + 1] = vInt[j]; } else break; } vInt[j + 1] = temp; } for (i = 0; i < n; ++i) cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FdyEGLp%2FbtqJHbK2thF%2Fo2kwKLhAYKa8oyktpHegj1%2Fimg.png)
[알고리즘 문제] 35. Special Sort(구글 인터뷰)
2020. 9. 28. 13:19
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i, j, temp; cin >> n; vector vInt(n); for (i = 0; i > vInt[i]; for (i = n - 1; i >= 0; --i) { for (j = 0; j 0 && vInt[j + 1] < 0) { temp = vInt[j]; vInt[j] = vInt[j + 1]; vInt[j + 1] = temp; } } } for (i = 0; i < n; ++i) cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fk6Cia%2FbtqJINiPl0m%2FWqKCLAas4Hqce7JWmXoszK%2Fimg.png)
[알고리즘 문제] 34. 버블정렬
2020. 9. 28. 13:12
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i, j, temp; cin >> n; vector vInt(n); for (i = 0; i > vInt[i]; for (i = n - 1; i >= 0; --i) { for(j = 0; j vInt[j+1]) { temp = vInt[j]; vInt[j] = vInt[j + 1]; vInt[j + 1] = temp; } } } for (i = 0; i < n; ++i) cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbj1DoU%2FbtqJFZDEUyj%2F4lS4ZrEI9PQXcKMt1YWC31%2Fimg.png)
[알고리즘 문제] 33. 3등의 성적은?
2020. 9. 27. 21:03
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, idx, temp, min = 2147000000, cnt = 0; cin >> n; vector vInt(n); for (int i = 0; i > vInt[i]; // 내림차순 선택 정렬 for (int i = 0; i vInt[idx]) idx = j; } temp = vInt[i]; vInt[i] = vInt[idx]; vInt[idx] = temp; } for (int i = 0; i < n; ++i) { i..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbb7csP%2FbtqJCSMtecj%2FUw6oWzV7IDOVxhJ3tRLCjK%2Fimg.png)
[알고리즘 문제] 32. 선택정렬
2020. 9. 27. 18:43
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, temp; cin >> n; vector vInt(n); for (int i = 0; i > vInt[i]; for (int i = 0; i vInt[j]) { temp = vInt[i]; vInt[i] = vInt[j]; vInt[j] = temp; } } } for (int i = 0; i > vInt[i]; for (..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fc6rKSf%2FbtqJIMqan4p%2FfaAE1dknaICCX5B9oolhpk%2Fimg.png)
[알고리즘 문제] 31. 탄화수소 질량
2020. 9. 27. 18:31
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { char c[10]; int i, pos, a = 0, b = 0; cin >> c; // C가 한 개인 경우 if(c[1] == 'H') { a = 1; pos = 1; } else { for(i = 1; c[i] != 'H'; ++i) { a = a * 10 + (c[i] - 48); } pos = i; } // H가 한 개인 경우 if (c[pos + 1] == '\0') b = 1; else { for(i = pos+1; c[i] != '\0'; ++i) { b = b * 10 + (c[i] - 48); } } cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbnIPIG%2FbtqJDXMABKq%2FxugMdtZOc8128k95vi3GI1%2Fimg.png)
[알고리즘 문제] 29. 3의 개수는? (small)
2020. 9. 26. 23:59
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, tmp, d, result = 0; cin >> n; for(int i = 1; i 0) { d = tmp % 10; if (d == 3) ++result; tmp /= 10; } } cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FYuVLy%2FbtqJCSd7GzJ%2FjMdcKVy8V0i9WS1z2n34K0%2Fimg.png)
[알고리즘 문제] 28. N!에서 0의 개수
2020. 9. 26. 23:48
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i, j, tmp, t = 0, f = 0; cin >> n; for(i = 2; i
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FzJvHi%2FbtqJHaqQnMx%2FBC7wPnnwSBnMsZ4wbWRXU1%2Fimg.png)
[알고리즘 문제] 27. N!의 표현법
2020. 9. 26. 22:55
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i, flag, a; cin >> n; vector vInt(n + 1); for (i = n; i >= 1; --i) { a = i; flag = 2; while(true) { if (a % flag == 0) { a = a / flag; vInt[flag]++; } else flag++; if (a == 1) break; } } cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FZUNS3%2FbtqJnE0jvKV%2FQslPP6NXNsBEeV7uYt5zn1%2Fimg.png)
[알고리즘 문제] 26. 마라톤
2020. 9. 22. 17:44
문제 풀이/알고리즘 문제풀이
코드 #include #include using namespace std; int main(void) { int n, i, j, num; cin >> n; vector vNum(n); for (i = 0; i > vNum[i]; // 기본값 1, 앞에를 돌면서 num = 1; for (j = 0; j < i; ++j) if (vNum[i]
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fb7J38x%2FbtqJltY0Nuh%2FeapkBYjYbzmSRztjUU0nt1%2Fimg.png)
[알고리즘 문제] 25. 석차 구하기
2020. 9. 22. 16:54
문제 풀이/알고리즘 문제풀이
코드 #include #include using namespace std; int main(void) { int n, i, j, num = 0; cin >> n; vector vScore(n); vector vResult(n); for (i = 0; i > vScore[i]; vResult[i] = 1; } for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { if (vScore[i] < vScore[j]) ++vResult[i]; } cout