diff --git a/2024-1/Basic/igaeun8/bfs/1012.cpp b/2024-1/Basic/igaeun8/bfs/1012.cpp new file mode 100644 index 00000000..f88e948b --- /dev/null +++ b/2024-1/Basic/igaeun8/bfs/1012.cpp @@ -0,0 +1,46 @@ +#include +#include +using namespace std; + +int t, m, n, k, x, y, ans; +int field[50][50]; +int xpos[4] = { 0, 0, -1, 1 }; +int ypos[4] = { 1, -1, 0, 0 }; + +void bfs(int x, int y) { + field[x][y] = 0; + for (int i = 0; i < 4; i++) { + int xx = x + xpos[i]; + int yy = y + ypos[i]; + if (xx < 0 || yy < 0 || xx >= m || yy >= n) continue; + if (field[xx][yy] == 1) { + bfs(xx, yy); + } + } +} + +int main() { + cin >> t; + for (int q = 0; q < t; q++) { + cin >> m >> n >> k; + for (int i = 0; i < k; i++) { + cin >> x >> y; + field[x][y] = 1; + } + + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (field[i][j] == 1) { + bfs(i, j); + ans++; + } + } + } + + cout << ans << '\n'; + ans = 0; + for (int i = 0; i < m; i++) { + fill(field[i], field[i] + n, 0); + } + } +} diff --git a/2024-1/Basic/igaeun8/recursion/10870.cpp b/2024-1/Basic/igaeun8/recursion/10870.cpp new file mode 100644 index 00000000..7cd52577 --- /dev/null +++ b/2024-1/Basic/igaeun8/recursion/10870.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int fibo(int num) { + if(num == 0) + return 0; + if(num == 1) + return 1; + return fibo(num-2) + fibo(num-1); +} + +int main() { + int n; + cin >> n; + cout << fibo(n); +} diff --git a/2024-1/Basic/igaeun8/recursion/10872.cpp b/2024-1/Basic/igaeun8/recursion/10872.cpp new file mode 100644 index 00000000..5cc9c897 --- /dev/null +++ b/2024-1/Basic/igaeun8/recursion/10872.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +int fact(int n) { + if (n <= 1) + return 1; + else + return n * fact(n - 1); +} + +int main() { + int n; + cin >> n; + cout << fact(n) << '\n'; +} diff --git a/2024-1/Basic/igaeun8/recursion/10974.cpp b/2024-1/Basic/igaeun8/recursion/10974.cpp new file mode 100644 index 00000000..e81ddcd4 --- /dev/null +++ b/2024-1/Basic/igaeun8/recursion/10974.cpp @@ -0,0 +1,20 @@ +#include +#include +#include + +using namespace std; + +int main(void) { + int n; + cin >> n; + + vector num(n); + for (int i = 0; i < n; i++) { + num[i] = i + 1; + } + do { + for (auto k : num) cout << k << " "; + cout << "\n"; + } while (next_permutation(num.begin(), num.end())); + +} diff --git a/2024-1/Basic/igaeun8/recursion/11050.cpp b/2024-1/Basic/igaeun8/recursion/11050.cpp new file mode 100644 index 00000000..ada317fc --- /dev/null +++ b/2024-1/Basic/igaeun8/recursion/11050.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +int facto(int num){ + if(num == 1) return 1; + if(num == 0) return 1; + else return facto(num-1)*num; +} + +int main(){ + int n, k; + cin >> n >> k; + cout << facto(n) / (facto(k) * facto(n-k)); + return 0; +} diff --git a/2024-1/Basic/igaeun8/recursion/2609.cpp b/2024-1/Basic/igaeun8/recursion/2609.cpp new file mode 100644 index 00000000..c5c36ffe --- /dev/null +++ b/2024-1/Basic/igaeun8/recursion/2609.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +//최대공약수 +int gcd(int a, int b) { + int c = a % b; + while (c != 0) { + a = b; + b = c; + c = a % b; + } + return b; +} + +//최소공배수 +int lcm(int a, int b) { + return (a * b) / gcd(a, b); +} + +int main() { + int n1, n2; + cin >> n1 >> n2; + cout << gcd(n1, n2) << "\n" << lcm(n1, n2); +}