![전체 글](https://t1.daumcdn.net/tistory_admin/static/manage/images/r3/default_L.png)
전체 글
[백준 14501] 퇴사 with Python
문제 링크 www.acmicpc.net/problem/14501 14501번: 퇴사 첫째 줄에 백준이가 얻을 수 있는 최대 이익을 출력한다. www.acmicpc.net 풀이 import sys n = int(sys.stdin.readline()) tp = [] for i in range(n): tp.append(tuple(map(int, sys.stdin.readline().split()))) maximum_profit = 0 def search_maximum_profit(start, acc=0): global maximum_profit profit = acc if start < n and start+tp[start][0]-1 < n: profit += tp[start][1] for i in range..
[백준 10996] 별 찍기 - 21 with Node.js
문제 링크 www.acmicpc.net/problem/10996 10996번: 별 찍기 - 21 예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요. www.acmicpc.net 풀이 const n = parseInt(require("fs").readFileSync("/dev/stdin").toString()); let piece = "*" + " *".repeat(Math.floor((n-1)/2)) + "\n" + " *".repeat(Math.floor(n/2)); for (let i=0; i
[백준 10808] 알파벳 개수 with Node.js
문제 링크 www.acmicpc.net/problem/10808 10808번: 알파벳 개수 단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다. www.acmicpc.net 풀이 const s = require("fs").readFileSync("/dev/stdin").toString().split(""); const alphabet = "abcdefghijklmnopqrstuvwxyz"; const counts = new Array(26).fill(0); s.forEach(i => counts[alphabet.indexOf(i)]++); console.log(counts.join(" ")); a부터 z까지 나열한 문자열과 26개의 0이 담긴 배열을 만든다. 그리고..
[백준 1002] 터렛 with Python
문제 링크 www.acmicpc.net/problem/1002 1002번: 터렛 각 테스트 케이스마다 류재명이 있을 수 있는 위치의 수를 출력한다. 만약 류재명이 있을 수 있는 위치의 개수가 무한대일 경우에는 -1을 출력한다. www.acmicpc.net 풀이 import sys t = int(sys.stdin.readline()) for i in range(t): x1, y1, r1, x2, y2, r2 = map(int, sys.stdin.readline().split()) d = ((x1-x2)**2 + (y1-y2)**2)**0.5 if x1 == x2 and y1 == y2 and r1 == r2: print(-1) elif d > r1 + r2: print(0) elif d == r1 + r2..
[백준 5585] 거스름돈 with Node.js
문제 링크 www.acmicpc.net/problem/5585 5585번: 거스름돈 타로는 자주 JOI잡화점에서 물건을 산다. JOI잡화점에는 잔돈으로 500엔, 100엔, 50엔, 10엔, 5엔, 1엔이 충분히 있고, 언제나 거스름돈 개수가 가장 적게 잔돈을 준다. 타로가 JOI잡화점에서 물건을 사 www.acmicpc.net 풀이 const money = parseInt(require("fs").readFileSync("/dev/stdin").toString()); let change = 1000 - money; let count = 0; const coins = [500, 100, 50, 10, 5, 1]; for (let i=0; i
[백준 1920] 수 찾기 with Python
문제 링크 www.acmicpc.net/problem/1920 1920번: 수 찾기 첫째 줄에 자연수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 N개의 정수 A[1], A[2], …, A[N]이 주어진다. 다음 줄에는 M(1 ≤ M ≤ 100,000)이 주어진다. 다음 줄에는 M개의 수들이 주어지는데, 이 수들 www.acmicpc.net 풀이 import sys n = int(sys.stdin.readline()) arr = sorted(list(map(int, sys.stdin.readline().split()))) m = int(sys.stdin.readline()) arr2 = list(map(int, sys.stdin.readline().split())) def search(nu..
[백준 2231] 분해합 with Node.js
문제 링크 www.acmicpc.net/problem/2231 2231번: 분해합 어떤 자연수 N이 있을 때, 그 자연수 N의 분해합은 N과 N을 이루는 각 자리수의 합을 의미한다. 어떤 자연수 M의 분해합이 N인 경우, M을 N의 생성자라 한다. 예를 들어, 245의 분해합은 256(=245+2+4+5)이 www.acmicpc.net 풀이 const num = parseInt(require("fs").readFileSync("/dev/stdin").toString()); let start = num - (num+"").length*9; let answer = 0; if (start ..
[백준 9012] 괄호 with Python
문제 링크 www.acmicpc.net/problem/9012 9012번: 괄호 괄호 문자열(Parenthesis String, PS)은 두 개의 괄호 기호인 ‘(’ 와 ‘)’ 만으로 구성되어 있는 문자열이다. 그 중에서 괄호의 모양이 바르게 구성된 문자열을 올바른 괄호 문자열(Valid PS, VPS)이라고 www.acmicpc.net 풀이 def vps(ps): left = 0 for i in ps: if i == "(": left += 1 else: left -= 1 if left < 0: return "NO" if left == 0: return "YES" else: return "NO" n = int(input()) for i in range(n): print(vps(input())) for문에..
[백준 10828] 스택 with Python
문제 링크 www.acmicpc.net/problem/10828 10828번: 스택 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 풀이 import sys n = int(input()) stack = [] for i in range(n): command = sys.stdin.readline().split() if len(command) == 2: stack.append(int(command[1])) else: if command[0] == "pop": if stack: print(stack.pop()) else..
[백준 10870] 피보나치 수 5 with Node.js
문제 링크 www.acmicpc.net/problem/10870 10870번: 피보나치 수 5 피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n ≥ 2)가 www.acmicpc.net 풀이 const fs = require("fs"); const n = fs.readFileSync("/dev/stdin"); function fibonacci(n) { if (n == 0) return 0; else if (n == 1) return 1; else return fibonacci(n-1) + fibonacci(n-2); } console.log(f..