![[백준 알고리즘] 7568번 덩치 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2Ft4vyr%2FbtqCF8aT4kB%2FAAAAAAAAAAAAAAAAAAAAAM52UNLs9OC5CqlivDabnsU0HnRUrFS6zdqB_muQXdJo%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DHB0QlK5Rb%252FBvhXonPExIBYoGtPI%253D)
N = int(input()) people = [] score = [1 for _ in range(N)] for _ in range(N): x_y = list(map(int, input().split())) people.append(x_y) for i in people: cnt = 1 for j in people: if i[0] < j[0] and i[1] < j[1]: cnt+=1 print(cnt, end=" ") ▼링크 https://www.acmicpc.net/problem/7568 7568번: 덩치 우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x,y)로 표시된다. 두 사람 A ..
![[백준 알고리즘] 2231번 분해합 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FbFOyQ7%2FbtqCJmsqzR1%2FAAAAAAAAAAAAAAAAAAAAAC-AojqC4fiFCKN2h3qZaaj57HWo885ZhVuIaxDx847u%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DNs6VuJMmbc6qWC%252BzpwD93UjfjwQ%253D)
N = int(input()) for num in range(1, N+1): num_list = list(map(int, str(num))) num_sum = num + sum(num_list) if num_sum == N: print(num) break if num==N: print(0) ▼ 링크 https://www.acmicpc.net/problem/2231 2231번: 분해합 문제 어떤 자연수 N이 있을 때, 그 자연수 N의 분해합은 N과 N을 이루는 각 자리수의 합을 의미한다. 어떤 자연수 M의 분해합이 N인 경우, M을 N의 생성자라 한다. 예를 들어, 245의 분해합은 256(=245+2+4+5)이 된다. 따라서 245는 256의 생성자가 된다. 물론, 어떤 자연수의 경우에는 생성자가 없을 ..
![[백준 알고리즘] 2798번 블랙잭 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FT6ezj%2FbtqCJmspL2h%2FAAAAAAAAAAAAAAAAAAAAAKo79UIG_pkTNymAVvue5PbcyyspjWeJ1O44MDrqJ5H6%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DCznCCO6u2wyRHXL8FKky8qCHJl8%253D)
import itertools N, M = map(int, input().split()) card = list(map(int, input().split())) ans = 0 for i in itertools.combinations(card, 3): card_sum = sum(i) if ans < card_sum and card_sum
![[백준 알고리즘] 2775번 부녀회장이 될테야 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2F627BI%2FbtqCJlz9gsj%2FAAAAAAAAAAAAAAAAAAAAAMpVEIe1Bj5RjzIKd8SZlNsMZQ5PkWC5RiV9yfVUCpbs%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DpSt2TqCvOE1gEjP21gNjecwjdbU%253D)
T = int(input()) for _ in range(T): floor = [] k = int(input()) n = int(input()) floor = [i for i in range(1, n+1)] for i in range(k): for j in range(1, n): floor[j] += floor[j-1] print(floor[-1]) ▼ 링크 https://www.acmicpc.net/problem/2775 2775번: 부녀회장이 될테야 첫 번째 줄에 Test case의 수 T가 주어진다. 그리고 각각의 케이스마다 입력으로 첫 번째 줄에 정수 k, 두 번째 줄에 정수 n이 주어진다. (1
![[백준 알고리즘] 1974번 스택 수열 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2Fbe8MOu%2FbtqCFxnHx2d%2FAAAAAAAAAAAAAAAAAAAAAFQr67amhLFVzKiVmrwmGeur4nLs-jZG6e_s1U7nmD4_%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3D7BiknO7cjfyn1kTCCSaMJ%252Fcpixs%253D)
N = int(input()) stack = [] check = 1 answer = [] possibility = True for i in range(N): num = int(input()) while check
![[백준 알고리즘] 4949번 균형잡힌 세상 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2Fdypcdu%2FbtqCGQNNf27%2FAAAAAAAAAAAAAAAAAAAAAD_ru5gnsRoaX6Mnbfu9mKoi2ZhVI6H8CzYbiIS5BF6J%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DAHgqWLDq7359Wm7HzXRcyziO%252BXc%253D)
while True: line = input() if line == ".": break stack = [] check = True for ch in line: if ch == "(" or ch == "[": stack.append(ch) elif ch == ")": if len(stack) == 0: check = False break if stack[-1] == "(": stack.pop() else: check = False break elif ch == "]": if len(stack) == 0: check = False break if stack[-1] == "[": stack.pop() else: check = False break if check and len(stack)==0: print("..
![[백준 알고리즘] 9012번 괄호 (Python, Java)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FbzkQIG%2FbtqCGReHHLk%2FAAAAAAAAAAAAAAAAAAAAAHdjEizdtdBZ-U1kuu6evpsw_oBceyN9OIjZ9qgGB-JG%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DZrzmAPpvzZsG6XOJTJu9bMm51KI%253D)
첫번째 코드 - 60ms import sys T = int(input()) for _ in range(T): line = sys.stdin.readline() bracket =[] cnt = 0 for ch in line: if cnt 0: bracket.pop() cnt -= 1 else: cnt = -1 break if cnt == 0: print("YES") else: print("NO") 처음에는 단순히 스택만 생각해서 리스트를 만들고 append하고 pop하는 방식으로 구현했는데 뭔가 코드가 더러워져서 다시 짰다. 코드 길이도 훨씬 짧고 시간도 훨씬..
![[백준 알고리즘] 10773번 제로 (Python, Java)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2Fqlsg6%2FbtqCB89Fik3%2FAAAAAAAAAAAAAAAAAAAAAE-d25L4B3lD2UA-ylIY7PdLWPgkK0EL_nFPJzlLzj_e%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DstGRcG388NTm1I1ezIW80QK09iQ%253D)
K = int(input()) list = [] for _ in range(K): n = int(input()) if n == 0: if len(list)>0: list.pop() else: list.append(n) print(sum(list)) import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(S..
![[백준 알고리즘] 10828번 스택 (Python, Java)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2Fk09vn%2FbtqCGRyHtF5%2FAAAAAAAAAAAAAAAAAAAAALUg680Xc26XCRNRcrR_iHp3Gbc5QGDNv8oQ6TjTq7TC%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DIYH8%252FN0gApzRfsoEVICMgLlGGXI%253D)
import sys N = int(input()) stack = [] for _ in range(N): line = sys.stdin.readline().split() if line[0] == "push": stack.append(int(line[1])) elif line[0] == "pop": if len(stack)>0: print(stack[-1]) stack.pop() else: print(-1) elif line[0] == "size": print(len(stack)) elif line[0] == "empty": if len(stack) == 0: print(1) else: print(0) elif line[0] == "top": if len(stack) > 0: print(stack[-1]) ..
![[백준 알고리즘] 1541번 잃어버린 괄호 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FcWUUK5%2FbtqCD7VFfwb%2FAAAAAAAAAAAAAAAAAAAAAILww2oYqmFprqa9FxS7212G5jui_Lnzj8gJTa8cbSEs%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DAOE99m722LlgiZint%252FR3ayHFSkY%253D)
import sys line = sys.stdin.readline() line = list(line.replace('-', ' ').split()) for num in line: if '+' in num: temp = list(map(int, num.split('+'))) s = sum(temp) line[line.index(num)] = s else: line[line.index(num)] = int(num) #단순 형변환 print(line[0]-sum(line[1:])) ▼ 링크 https://www.acmicpc.net/problem/1541