-
알고리즘 & 자료구조 스터디(10조) 5일차알고리즘 2023. 5. 26. 21:37
Q. 4949 균형 잡힌 세상
멘붕입니다.. 머리가 많이 아파요 거의 다 풀 뻔 했는데 못해서 너무 힘들어요 살려주세요..
Q. 1978 소수 찾기
n = int(input()) arr = list(map(int,input().split())) count = len(arr) for i in arr: if i == 1: count -= 1 elif i == 2: continue for j in range(2,i): if i % j == 0: count -= 1 break print(count)
Q. 10866 덱
from collections import deque import sys n = int(input()) q= deque() for i in range(n): data = list(sys.stdin.readline().split()) if data[0] == "push_front": q.appendleft(data[1]) elif data[0] == 'push_back': q.append(data[1]) elif data[0] == 'pop_front': if len(q) !=0: print(q.popleft()) else: print(-1) elif data[0] == 'pop_back': if len(q) !=0: print(q.pop()) else: print(-1) elif data[0] == 'size': print(len(q)) elif data[0] == 'empty': print(int(bool(not q))) elif data[0] == 'front': if len(q) : print(q[0]) else: print(-1) elif data[0] == 'back': if len(q): print(q[-1]) else: print(-1)
Q 11866 요세푸스 0
from collections import deque n , m = map(int, input().split()) deq = deque() for i in range(1, n + 1): deq.append(str(i)) list = [] # <3, 6, 2, 7, 5, 1, 4> while len(deq) != 0: deq.rotate(-(m-1)) list.append(deq[0]) deq.popleft() result = ", ".join(list) print(f"<{result}>")
'알고리즘' 카테고리의 다른 글
알고리즘 & 자료구조 스터디(10조) 7일차 (0) 2023.05.29 알고리즘 & 자료구조 스터디(10조) 6일차 (0) 2023.05.27 알고리즘 & 자료구조 스터디(10조) 4일차 (1) 2023.05.25 알고리즘 & 자료구조 스터디(10조) 3일차 (0) 2023.05.24 알고리즘 & 자료구조 스터디(10조) 2일차 (0) 2023.05.23