목록알고리즘 (28)
안선생의 개발 블로그
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130#include using namespace std;class Node {public: int data; Node* Next;};class LinkedList{private: Node* first;public..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 12..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #include using namespace std; int main() { //Anagram 두 문자열에 알파벳이 같다. // 1. 두 문자열의 크기가 동일한지 char a[] = "zeio"; char b[] = "eioz"; int count=0,count1=0; int h[26] ={}; for (int i = 0; a[i] != NULL; i++) { h[a[i]-97]++; count++; } for (int i = 0; b[i] != NULL; i++) { h[b[i] - 97]--; //+1된 부분을..
c언어 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 12..

하노이 탑에는 조건이 있다. 1. 한 번에 한 개의 원판만을 다른 탑으로 옮길 수 있다. 2. 쌓아 놓은 원판은 항상 위의 것이 아래의 것보다 작아야 한다. n개의 원판이 있고 a에서 c까지 보낸다고 했을 떄 예를 보자 n이 1인 경우 이 경우는 바로 c까지 보내면 된다. cout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 #include using namespace std; int f[10] = {}; // 전역변수 int fibo(int n) // 반복문을 이용한 피보나치 { int s = 0, f0=0, f1=1; if (n
일반재귀 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include using namespace std; int fun(int n) { if (n > 0) { return fun(n - 1)+n; } return 0; } int main() { int x; x=fun(5); cout fun(2) +n-> fun(1)+n ->fun(0)+n 조건문에 걸려서 반대로 올라간다. n은 1부터 시작해서 올라간다. fun(0) = 0+1 = 1 fun(1) = 1 +2 = 3 fun(2) = 3 +3 = 6 fun(3) = 6 +4 = 10 fun(4) = 10 +5 = 15 fun(5) = 15 결과값은 15가 나온다. 정적변수를 이용 1 2 3 4 5 6 7 8 ..