Skip to content

kangdy25 / 4월 3주차~5월 4주차 / 19문제 #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions kangdy25/BOJ/1010.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 다리 놓기 / 실버 5

#include <bits/stdc++.h>
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";
}
29 changes: 29 additions & 0 deletions kangdy25/BOJ/10773.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 제로 / 실버 4

#include <bits/stdc++.h>
using namespace std;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

int K, num, total = 0;
cin >> K;
stack<int> 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";
}
24 changes: 24 additions & 0 deletions kangdy25/BOJ/10870.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 피보나치 수 5 / 브론즈 2

#include <bits/stdc++.h>
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";
}
15 changes: 15 additions & 0 deletions kangdy25/BOJ/10872.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 팩토리얼 / 브론즈 3
#include <iostream>
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;
}
25 changes: 25 additions & 0 deletions kangdy25/BOJ/11050.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 이항 계수 1 / 브론즈 1

#include <bits/stdc++.h>
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";
}
31 changes: 31 additions & 0 deletions kangdy25/BOJ/11866.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 요세푸스 문제 0 / 실버 5

#include <bits/stdc++.h>
using namespace std;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

int N, K;
cin >> N >> K;
queue<int> 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 << ">";
}
32 changes: 32 additions & 0 deletions kangdy25/BOJ/12789.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 도키도키 간식드리미 / 실버 3

#include <bits/stdc++.h>
using namespace std;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

int N, num, cnt = 1;
cin >> N;
stack<int> 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";
}
}
13 changes: 13 additions & 0 deletions kangdy25/BOJ/15439.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 베라의 패션 / 브론즈 4
#include <bits/stdc++.h>
using namespace std;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

int N;
cin >> N;

cout << N * (N - 1);
}
49 changes: 49 additions & 0 deletions kangdy25/BOJ/18258.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 큐 2 / 실버 4

#include <bits/stdc++.h>
using namespace std;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

int N, num;
string s;
queue<int> 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";
}
}
}
}
34 changes: 34 additions & 0 deletions kangdy25/BOJ/2164.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 카드2 / 실버 4

#include <bits/stdc++.h>
using namespace std;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

int N;
cin >> N;
queue<int> 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";
}
}
39 changes: 39 additions & 0 deletions kangdy25/BOJ/2346.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 풍선 터뜨리기 / 실버 3

#include <bits/stdc++.h>
using namespace std;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

int N, pop, coord, popTargetValue, popTargetCoord;
cin >> N;
deque<pair<int, int>> 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();
}
}
}
}
35 changes: 35 additions & 0 deletions kangdy25/BOJ/24511.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// queuestack / 실버 3

#include <bits/stdc++.h>
using namespace std;

int N, M, check, queuestack[100001];
deque<int> 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();
}

}
16 changes: 16 additions & 0 deletions kangdy25/BOJ/24723.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 녹색거탑 / 브론즈 4
#include <bits/stdc++.h>
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";
}
Loading