파이썬59 [백준 10866] 덱 - Python(파이썬) from collections import deque import sys N = int(sys.stdin.readline().strip()) my_d = deque() for _ in range(N): order = list(map(str, sys.stdin.readline().split())) if order[0] == 'push_back': my_d.append(order[1]) elif order[0] == 'push_front': my_d.appendleft(order[1]) elif order[0] == 'pop_front': print(my_d.popleft() if my_d else -1) elif order[0] == 'pop_back': print(my_d.pop() if my_d els.. 2021. 2. 15. [백준 1966] 프린터 큐 - Python(파이썬) from collections import deque import sys T = int(sys.stdin.readline().strip()) for tc in range(T): N, M = map(int, sys.stdin.readline().split()) arr = deque(map(int, sys.stdin.readline().split())) cnt = 1 while True: if len(arr) == 1: print(cnt) break x = arr.popleft() if x >= max(arr): if M == 0: print(cnt) break else: M -= 1 cnt += 1 else: if M == 0: M = len(arr) else: M -= 1 arr.append(x) 2021. 2. 15. [백준 11866] 요세푸스 문제 0 - Python(파이썬) import sys N, K = map(int, sys.stdin.readline().split()) my_data = list(range(1, N+1)) NN = N cnt = 0 idx = 0 key = 1 result = [] while cnt != NN: # K배수 찾기 if key % K == 0: result.append(my_data.pop(idx % N)) # cnt 개수 1개 늘리고 K배수 찾는 변수 초기화 cnt += 1 key = 0 # 인덱스를 현재 length에 맞게 설정 idx %= N idx -= 1 N -= 1 idx += 1 key += 1 print('') 2021. 2. 15. [백준 2164] 카드2 - Python(파이썬) from collections import deque import sys N = int(sys.stdin.readline().strip()) my_card = deque(list(range(1, N+1))) while len(my_card) != 1: my_card.popleft() my_card.append(my_card.popleft()) print(*my_card) 2021. 2. 15. [백준 18258] 큐 2 - Python(파이썬) from collections import deque import sys N = int(sys.stdin.readline().strip()) my_deq = deque() for _ in range(N): order = list(map(str, sys.stdin.readline().split())) if order[0] == 'push': my_deq.append(order[1]) elif order[0] == 'pop': print(my_deq.popleft() if my_deq else -1) elif order[0] == 'size': print(len(my_deq)) elif order[0] == 'empty': print(0 if my_deq else 1) elif order[0] == 'fro.. 2021. 2. 15. 이전 1 ··· 7 8 9 10 다음