diff --git a/kangdy25/BOJ/1010.cpp b/kangdy25/BOJ/1010.cpp new file mode 100644 index 000000000..779042235 --- /dev/null +++ b/kangdy25/BOJ/1010.cpp @@ -0,0 +1,24 @@ +// 다리 놓기 / 실버 5 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N, K, result = 1; + cin >> N >> K; + int NK = N - K; + + for (int i = N; i >= 1; i--) { + result *= i; + } + for (int j = K; j >= 1; j--) { + result /= j; + } + for (int j = NK; j >= 1; j--) { + result /= j; + } + cout << result << "\n"; +} \ No newline at end of file diff --git a/kangdy25/BOJ/10773.cpp b/kangdy25/BOJ/10773.cpp new file mode 100644 index 000000000..28662b576 --- /dev/null +++ b/kangdy25/BOJ/10773.cpp @@ -0,0 +1,29 @@ +// 제로 / 실버 4 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int K, num, total = 0; + cin >> K; + stack money; + + while (K--) { + cin >> num; + if (num == 0) { + money.pop(); + } + else { + money.push(num); + } + } + + while (!money.empty()) { + total += money.top(); + money.pop(); + } + cout << total << "\n"; +} \ No newline at end of file diff --git a/kangdy25/BOJ/10870.cpp b/kangdy25/BOJ/10870.cpp new file mode 100644 index 000000000..45e6cdc52 --- /dev/null +++ b/kangdy25/BOJ/10870.cpp @@ -0,0 +1,24 @@ +// 피보나치 수 5 / 브론즈 2 + +#include +using namespace std; + +int Fibonacci(int n) { + if (n == 0) { + return 0; + } else if (n == 1) { + return 1; + } else { + return Fibonacci(n - 2) + Fibonacci(n - 1); + } +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N; + cin >> N; + + cout << Fibonacci(N) << "\n"; +} \ No newline at end of file diff --git a/kangdy25/BOJ/10872.cpp b/kangdy25/BOJ/10872.cpp new file mode 100644 index 000000000..516a921d1 --- /dev/null +++ b/kangdy25/BOJ/10872.cpp @@ -0,0 +1,15 @@ +// 팩토리얼 / 브론즈 3 +#include +using namespace std; + +int factorial(int n) { + if (n == 0) return 1; + else return n * factorial(n - 1); +} + +int main() { + int N; + cin >> N; + cout << factorial(N); + return 0; +} \ No newline at end of file diff --git a/kangdy25/BOJ/11050.cpp b/kangdy25/BOJ/11050.cpp new file mode 100644 index 000000000..90e022c33 --- /dev/null +++ b/kangdy25/BOJ/11050.cpp @@ -0,0 +1,25 @@ +// 이항 계수 1 / 브론즈 1 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N, K, result = 1; + cin >> N >> K; + int NK = N - K; + + + for (int i = N; i >= 1; i--) { + result *= i; + } + for (int j = K; j >= 1; j--) { + result /= j; + } + for (int j = NK; j >= 1; j--) { + result /= j; + } + cout << result << "\n"; +} \ No newline at end of file diff --git a/kangdy25/BOJ/11866.cpp b/kangdy25/BOJ/11866.cpp new file mode 100644 index 000000000..6dda15e88 --- /dev/null +++ b/kangdy25/BOJ/11866.cpp @@ -0,0 +1,31 @@ +// 요세푸스 문제 0 / 실버 5 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N, K; + cin >> N >> K; + queue q; + + for (int i = 1; i <= N; i++) { + q.push(i); + } + + cout << "<"; + while (!q.empty()) { + for (int i = 1; i < K; i++) { + q.push(q.front()); + q.pop(); + } + cout << q.front(); + if (q.size() > 1) { + cout << ", "; + } + q.pop(); + } + cout << ">"; +} \ No newline at end of file diff --git a/kangdy25/BOJ/12789.cpp b/kangdy25/BOJ/12789.cpp new file mode 100644 index 000000000..84bd25da7 --- /dev/null +++ b/kangdy25/BOJ/12789.cpp @@ -0,0 +1,32 @@ +// 도키도키 간식드리미 / 실버 3 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N, num, cnt = 1; + cin >> N; + stack st; + + for (int i = 0; i < N; i++) { + cin >> num; + if (num == cnt) { + cnt++; + } else { + st.push(num); + } + + while(!st.empty() && st.top() == cnt) { + st.pop(); + cnt++; + } + } + if (st.empty()) { + cout << "Nice\n"; + } else { + cout << "Sad\n"; + } +} \ No newline at end of file diff --git a/kangdy25/BOJ/15439.cpp b/kangdy25/BOJ/15439.cpp new file mode 100644 index 000000000..778c32c64 --- /dev/null +++ b/kangdy25/BOJ/15439.cpp @@ -0,0 +1,13 @@ +// 베라의 패션 / 브론즈 4 +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N; + cin >> N; + + cout << N * (N - 1); +} \ No newline at end of file diff --git a/kangdy25/BOJ/18258.cpp b/kangdy25/BOJ/18258.cpp new file mode 100644 index 000000000..2eec5cc6a --- /dev/null +++ b/kangdy25/BOJ/18258.cpp @@ -0,0 +1,49 @@ +// 큐 2 / 실버 4 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N, num; + string s; + queue q; + cin >> N; + + while(N--) { + cin >> s; + if (s == "push") { + cin >> num; + q.push(num); + } else if (s == "pop") { + if (!q.empty()) { + cout << q.front() << "\n"; + q.pop(); + } else { + cout << "-1\n"; + } + } else if (s == "size") { + cout << q.size() << "\n"; + } else if (s == "empty") { + if (q.empty()) { + cout << "1\n"; + } else { + cout << "0\n"; + } + } else if (s == "front") { + if (q.empty()) { + cout << "-1\n"; + } else { + cout << q.front() << "\n"; + } + } else if (s == "back") { + if (q.empty()) { + cout << "-1\n"; + } else { + cout << q.back() << "\n"; + } + } + } +} \ No newline at end of file diff --git a/kangdy25/BOJ/2164.cpp b/kangdy25/BOJ/2164.cpp new file mode 100644 index 000000000..bdf0811c9 --- /dev/null +++ b/kangdy25/BOJ/2164.cpp @@ -0,0 +1,34 @@ +// 카드2 / 실버 4 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N; + cin >> N; + queue q; + bool check = true; + + for (int i = 1; i <= N; i++) { + q.push(i); + } + if (N == 1) { + cout << "1\n"; + } else { + while(q.size() != 1) { + if (check) { + q.pop(); + check = false; + } else { + q.push(q.front()); + q.pop(); + check = true; + } + N--; + } + cout << q.back() << "\n"; + } +} \ No newline at end of file diff --git a/kangdy25/BOJ/2346.cpp b/kangdy25/BOJ/2346.cpp new file mode 100644 index 000000000..7f235e617 --- /dev/null +++ b/kangdy25/BOJ/2346.cpp @@ -0,0 +1,39 @@ +// 풍선 터뜨리기 / 실버 3 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N, pop, coord, popTargetValue, popTargetCoord; + cin >> N; + deque> dq; + + for (int i = 1; i <= N; i++) { + cin >> coord; + dq.push_back(make_pair(coord, i)); + } + + while (!dq.empty()) { + popTargetCoord = dq.front().first; + popTargetValue = dq.front().second; + + cout << popTargetValue << " "; + dq.pop_front(); + + if (!dq.empty() && popTargetCoord > 0) { + for (int i = 1; i < popTargetCoord; i++) { + dq.push_back(dq.front()); + dq.pop_front(); + } + } + else if (!dq.empty() && popTargetCoord < 0) { + for (int i = 1; i < popTargetCoord * (-1) + 1; i++) { + dq.push_front(dq.back()); + dq.pop_back(); + } + } + } +} \ No newline at end of file diff --git a/kangdy25/BOJ/24511.cpp b/kangdy25/BOJ/24511.cpp new file mode 100644 index 000000000..cf71a16fd --- /dev/null +++ b/kangdy25/BOJ/24511.cpp @@ -0,0 +1,35 @@ +// queuestack / 실버 3 + +#include +using namespace std; + +int N, M, check, queuestack[100001]; +deque dq; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + cin >> N; + for (int i = 0; i < N; i++) { + cin >> check; + queuestack[i] = check; + } + for (int i = 0; i < N; i++) { + int x; + cin >> x; + if (queuestack[i] == 0) { + dq.push_back(x); + } + } + + cin >> M; + for (int i = 0; i < M; i++) { + int x; + cin >> x; + dq.push_front(x); + cout << dq.back() << " "; + dq.pop_back(); + } + +} \ No newline at end of file diff --git a/kangdy25/BOJ/24723.cpp b/kangdy25/BOJ/24723.cpp new file mode 100644 index 000000000..add0d18cd --- /dev/null +++ b/kangdy25/BOJ/24723.cpp @@ -0,0 +1,16 @@ +// 녹색거탑 / 브론즈 4 +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N, result = 1; + cin >> N; + + for (int i = 1; i <= N; i++) { + result *= 2; + } + cout << result << "\n"; +} \ No newline at end of file diff --git a/kangdy25/BOJ/25501.cpp b/kangdy25/BOJ/25501.cpp new file mode 100644 index 000000000..4b61db596 --- /dev/null +++ b/kangdy25/BOJ/25501.cpp @@ -0,0 +1,38 @@ +// 재귀의 귀재 / 브론즈 2 +#include +using namespace std; + +int cnt = 0; + +int recursion(const char* s, int l, int r) { + cnt++; + if (l >= r) { + return 1; + } + else if (s[l] != s[r]) { + return 0; + } + else { + return recursion(s, l + 1, r - 1); + } +} + +int isPalindrome(const char* s) { + return recursion(s, 0, strlen(s) - 1); +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int T; + string S; + cin >> T; + + for (int i = 0; i < T; i++) { + cnt = 0; + cin >> S; + cout << isPalindrome(S.c_str()) << " " << cnt << "\n"; + } + +} \ No newline at end of file diff --git a/kangdy25/BOJ/27433.cpp b/kangdy25/BOJ/27433.cpp new file mode 100644 index 000000000..00e2c7865 --- /dev/null +++ b/kangdy25/BOJ/27433.cpp @@ -0,0 +1,22 @@ +// 팩토리얼 2 / 브론즈 5 + +#include +using namespace std; + +long long Factorial(long long a) { + if (a == 0 || a == 1) { + return 1; + } else { + return a * Factorial(a-1); + } +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + long long N; + cin >> N; + + cout << Factorial(N) << "\n"; +} diff --git a/kangdy25/BOJ/28278.cpp b/kangdy25/BOJ/28278.cpp new file mode 100644 index 000000000..9eeeec53d --- /dev/null +++ b/kangdy25/BOJ/28278.cpp @@ -0,0 +1,50 @@ +// 스택 2 / 실버 4 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N, cmd, x; + cin >> N; + stack s; + + while(N--) { + cin >> cmd; + switch (cmd) { + case 1: + cin >> x; + s.push(x); + break; + case 2: + if (s.empty()) { + cout << "-1\n"; + } else { + cout << s.top() << "\n"; + s.pop(); + } + break; + case 3: + cout << s.size() << "\n"; + break; + case 4: + if (s.empty()) { + cout << "1\n"; + } else { + cout << "0\n"; + } + break; + case 5: + if (s.empty()) { + cout << "-1\n"; + } else { + cout << s.top() << "\n"; + } + break; + default: // do nothing + break; + } + } +} \ No newline at end of file diff --git a/kangdy25/BOJ/28279.cpp b/kangdy25/BOJ/28279.cpp new file mode 100644 index 000000000..3ec790e13 --- /dev/null +++ b/kangdy25/BOJ/28279.cpp @@ -0,0 +1,69 @@ +// 덱 2 / 실버 4 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N, cmd, num; + cin >> N; + deque dq; + + while(N--) { + cin >> cmd; + switch (cmd) { + case 1: + cin >> num; + dq.push_front(num); + break; + case 2: + cin >> num; + dq.push_back(num); + break; + case 3: + if (!dq.empty()) { + cout << dq.front() << "\n"; + dq.pop_front(); + } else { + cout << "-1\n"; + } + break; + case 4: + if (!dq.empty()) { + cout << dq.back() << "\n"; + dq.pop_back(); + } else { + cout << "-1\n"; + } + break; + case 5: + cout << dq.size() << "\n"; + break; + case 6: + if (!dq.empty()) { + cout << "0\n"; + } else { + cout << "1\n"; + } + break; + case 7: + if (!dq.empty()) { + cout << dq.front() << "\n"; + } else { + cout << "-1\n"; + } + break; + case 8: + if (!dq.empty()) { + cout << dq.back() << "\n"; + } else { + cout << "-1\n"; + } + break; + default: + break; + } + } +} \ No newline at end of file diff --git a/kangdy25/BOJ/4949.cpp b/kangdy25/BOJ/4949.cpp new file mode 100644 index 000000000..289992ebd --- /dev/null +++ b/kangdy25/BOJ/4949.cpp @@ -0,0 +1,55 @@ +// 균형잡힌 세상 / 실버 4 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + string s = ""; + + while (true) { + bool check = true; + getline(cin, s); + stack st; + + if (s[0] == '.') { + break; + } + + for (int i = 0; i < s.size(); i++) { + if (s[i] == '[' || s[i] == '(') { + st.push(s[i]); + } + else if (s[i] == ']') { + if (!st.empty() && st.top() == '[') { + st.pop(); + } + else { + cout << "no\n"; + check = false; + break; + } + } + else if (s[i] == ')') { + if (!st.empty() && st.top() == '(') { + st.pop(); + } + else { + cout << "no\n"; + check = false; + break; + } + } + } + if (check) { + if (st.empty()) { + cout << "yes\n"; + } + else { + cout << "no\n"; + } + } + } +} \ No newline at end of file diff --git a/kangdy25/BOJ/9012.cpp b/kangdy25/BOJ/9012.cpp new file mode 100644 index 000000000..94567f460 --- /dev/null +++ b/kangdy25/BOJ/9012.cpp @@ -0,0 +1,43 @@ +// 괄호 / 실버 4 + +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int N; + cin >> N; + string s; + + while (N--) { + bool check = true; + cin >> s; + stack st; + for (int i = 0; i < s.size(); i++) { + if (s[i] == '(') { + st.push(s[i]); + } + else { + if (!st.empty() && st.top() == '(') { + st.pop(); + } + else { + cout << "NO\n"; + check = false; + break; + } + } + } + if (check) { + if (st.empty()) { + cout << "YES\n"; + } + else { + cout << "NO\n"; + } + + } + } +} \ No newline at end of file