본문 바로가기

Programming/Algorithm

[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")} 더보기
[c++] 백준 - 치킨 배달 (15686번) https://www.acmicpc.net/problem/15686 15686번: 치킨 배달 크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸 www.acmicpc.net DFS의 응용문제로 보이고, vector와 구조체를 활용하면 간단하게 연산이 가능하다. #include #include #include using namespace std; int N, M; int map[51][51]; int minLength = 100000000; typedef struct { int x; int y; int len; }house; vector h; ty.. 더보기