본문 바로가기

알고리즘/백준 (Pyhthon)

(79)
[알고리즘] 백준 1920 수찾기 n = int(input()) nn = set(map(int, input().split())) m = int(input()) mm = list(map(int, input().split())) for i in range(m): if mm[i] in nn: print('1') else: print('0') 더 최적화 시킨 코드 N, A = int(input()), {i:1 for i in map(int, input().split())} M = int(input()) for i in list(map(int, input().split())): print(A.get(i, 0)) 딕셔너리를 confrehension으로 만들기 for문으로 입력받기 get함수를 이용해 1 또는 0 출력
[알고리즘] 백준 10930 SHA-256 import hashlib data = input() en_data = data.encode() result = hashlib.sha256(en_data).hexdigest() print(result)
[알고리즘] 백준 5397 키로거 test_case = int(input()) for _ in range(test_case): stack1 = [] stack2 = [] str = input() for i in range(len(str)): if str[i] == '>': if stack2: stack1.append(stack2.pop()) elif str[i] == '
[알고리즘] 백준 1966 프린터큐 im_list #우선순위 입력 리스트 im_list2 #우선순위 입력 리스트 복사, max값 확인용 result #n의 크기만큼 초기화해놓고 인쇄순서 넣음 queue #index용 배열 test_case = int(input()) for _ in range(test_case): n, m = map(int, input().split(' ')) im_list = list(map(int, input().split(' '))) im_list2 = [] for i in im_list: im_list2.append(i) result = [0 for _ in range(n)] queue = [i for i in range(n)] count = 1 while queue: if im_list[queue[0]] == ma..
[알고리즘] 백준 1874 스택수열 n = int(input()) stack_list = list() pm_list = list() count = 1 for i in range(1,n+1): num = int(input()) while count
[알고리즘] 백준 2798 블랙잭 n, m = input().split() n = int(n) m = int(m) card_num = list(map(int, input().split())) sum = list() for i in range(0, n-2): for j in range(i+1, n-1): for k in range(j+1, n): sum.append(card_num[i] + card_num[j] + card_num[k]) result = 0 for i in sum: if i
[알고리즘] 백준 2920 음계 num_list = list(map(int,input().split())) count1,count2 = 0,0 for i in range(8): if num_list[i] == i+1: count1 += 1 elif num_list[i] == 8-i: count2 += 1 if count1 == 8: print("ascending") elif count2 == 8: print("descending") else: print("mixed") list(map(int, input().split))은 list[0]부터 sapce로 구분하여 입력받는 것 num_list = list(map(int,input().split())) ascending = True descending = True for i in range..