본문 바로가기

분류 전체보기

[Python] 백준 4195번 : 친구 네트워크 def find(x): if x == parent[x]: return x else: p = find(parent[x]) parent[x] = p return p def union(x, y): x = find(x) y = find(y) if x != y: parent[y] = x number[x] += number[y] test_case = int(input()) for _ in range(test_case): parent = dict() number = dict() f = int(input()) for _ in range(f): x, y = input().split(' ') if x not in parent: parent[x] = x number[x] = 1 if y not in parent: paren.. 더보기
[Python] 백준 1920번 : 수 찾기 N = int(input()) A = set(map(int, input().split(' '))) M = int(input()) M_lis = list(map(int, input().split(' '))) for m in M_lis: if m in A: print('1') else: print('0') 더보기
[Python] 백준 10930번 : SHA-256 import hashlib a = input() print(hashlib.sha256(a.encode()).hexdigest()) 더보기
[Python] 백준 5397번 : 키로거 test_case = int(input()) for _ in range(test_case): left_stack = [] right_stack = [] data = input() for i in data: if i == '-': if left_stack: left_stack.pop() elif i == '': if right_stack: left_stack.append(right_stack.pop()) else: left_stack.append(i) left_stack.extend(reversed(right_stack)) print(''.join(left_stack)) 더보기
[Python] 백준 1966번 : 프린터 큐 test_case = int(input()) for _ in range(test_case): n, m = list(map(int, input().split(' '))) doc = list(map(int, input().split(' '))) # doc = [[i, idx] for idx, i in enumerate(doc)] doc = [t for t in enumerate(doc)] cnt = 0 while True: if doc[0][1] == max(doc, key=lambda x:x[1])[1]: cnt += 1 if doc[0][0] == m: print(cnt) break else: doc.pop(0) else: doc.append(doc.pop(0)) 더보기
[Python] 백준 1874번 : 스택수열 n = int(input()) count = 1 stack = [] result = [] for i in range(1, n + 1): # 데이터 개수만큼 반복 data = int(input()) while count 더보기
[Python] 백준 2798번 : 블랙잭 n, M = list(map(int, input().split(' '))) data = list(map(int, input().split(' '))) length = len(data) approx = 0 for i in range(0, length - 2): if data[i] >= M: continue for j in range(i + 1, length -1): if data[i] + data[j] >= M: continue for k in range(j + 1, length): if data[k] + data[i] + data[j] = abs(M - sum): approx = sum print(approx) 더보기
[Python] 백준 2920번 : 음계 x = list(map(int, input().split())) if x == sorted(x): print("ascending") elif x == sorted(x, reverse=True): print("descending") else: print("mixed")} 더보기