백준 14916번
·
Study/Algorithm
https://www.acmicpc.net/problem/14916 14916번: 거스름돈 첫째 줄에 거스름돈 액수 n(1 ≤ n ≤ 100,000)이 주어진다. www.acmicpc.net #include using namespace std; int main() { int money, result; cin >> money; bool success = false; int five = money / 5; while (!success) { float two = (money - five * 5) % 2; if (two == 0) { success = true; result = five + (money - five * 5) / 2; } else { five--; } } if (money == 1 || money..
백준 1021번
·
Study/Algorithm
https://www.acmicpc.net/problem/1021 1021번: 회전하는 큐 첫째 줄에 큐의 크기 N과 뽑아내려고 하는 수의 개수 M이 주어진다. N은 50보다 작거나 같은 자연수이고, M은 N보다 작거나 같은 자연수이다. 둘째 줄에는 지민이가 뽑아내려고 하는 수의 위치가 www.acmicpc.net #include #include using namespace std; int main(int argc, char** argv) { deque Deque; int left, right; int cnt = 0; int N, M; cin >> N >> M; for (int i = 1; i num; for (int i = 0; i
백준 1068번
·
Study/Algorithm
https://www.acmicpc.net/problem/1068 1068번: 트리 첫째 줄에 트리의 노드의 개수 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄에는 0번 노드부터 N-1번 노드까지, 각 노드의 부모가 주어진다. 만약 부모가 없다면 (루트) -1이 주어진다 www.acmicpc.net #include #include #include using namespace std; vector node; int N; int answer = 0; int target; void Count(int now_node) { if (now_node == target) return; int now_node_size = node[now_node].size(); switch (now_node_size)..
백준 14501번
·
Study/Algorithm
https://www.acmicpc.net/problem/14501 14501번: 퇴사 첫째 줄에 백준이가 얻을 수 있는 최대 이익을 출력한다. www.acmicpc.net #include using namespace std; int t[1000] = { 0, }; int p[1000] = { 0, }; int dp[1000] = { 0, }; int max(int x, int y) { return x > y ? x : y; } int main() { int N; int next; cin >> N; for (int i = 1; i > t[i] >> p[i]; } for (int i = N; i > 0; i--) { next = i + t[i]; if (next > N + 1) { dp[i] = dp[i ..
백준 1874번
·
Study/Algorithm
https://www.acmicpc.net/problem/1874 1874번: 스택 수열 1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다. www.acmicpc.net #include #include #include using namespace std; int main() { stack s; vector result; vector input; int n; cin >> n; for (int i = 0; i > x; input.push_bac..
백준 9935번
·
Study/Algorithm
https://www.acmicpc.net/problem/9935 9935번: 문자열 폭발 첫째 줄에 문자열이 주어진다. 문자열의 길이는 1보다 크거나 같고, 1,000,000보다 작거나 같다. 둘째 줄에 폭발 문자열이 주어진다. 길이는 1보다 크거나 같고, 36보다 작거나 같다. 두 문자열은 모 www.acmicpc.net #include #include using namespace std; int main() { vectorv; string input, bomb; cin >> input >> bomb; for (int i = 0; i = bomb.size()) { bool result = tru..
백준 1991번
·
Study/Algorithm
https://www.acmicpc.net/problem/1991 1991번: 트리 순회 첫째 줄에는 이진 트리의 노드의 개수 N(1 ≤ N ≤ 26)이 주어진다. 둘째 줄부터 N개의 줄에 걸쳐 각 노드와 그의 왼쪽 자식 노드, 오른쪽 자식 노드가 주어진다. 노드의 이름은 A부터 차례대로 알파 www.acmicpc.net #include #include using namespace std; struct treestruct { char left; char right; }; map tree; void preorder(char node) { if (node == '.') return; cout second.left); preorder(tree.find(node)->second.right); } void ino..
백준 11279번
·
Study/Algorithm
https://www.acmicpc.net/problem/11047 11047번: 동전 0 첫째 줄에 N과 K가 주어진다. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000) 둘째 줄부터 N개의 줄에 동전의 가치 Ai가 오름차순으로 주어진다. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2인 경우에 Ai는 Ai-1의 배수) www.acmicpc.net #include #include using namespace std; int main() { int n, goal; cin >> n >> goal; stack s; for (int i = 0; i > input; s.push(input); } int result = 0; while (..