-
[큐] 1966 프린터 큐백준 Online Judge 2022. 1. 19. 21:09
백준 문제 1966
- 난이도: 하
- 문제 유형: 큐, 구현, 그리디

enumerate 함수 설명
순서가 있는 자료형 (e.g. 리스트, 튜플, 문자열)을 입력 받아서 인덱스 값과 함께 보여준다.
>>> for i, name in enumerate(['kim', 'han', 'park']): print(i, name) 0 kim 1 han 2 park문제 풀이 코드
test_case = int(input()) for _ in range(test_case): n, m = list(map(int, input().split(' '))) queue = list(map(int, input().split(' '))) # 튜플 형식으로 넣는다. [2, 1, 4, 3] -> [(2, 0), (1, 1), (4, 2), (3,3)] 이런 식으로 인덱스 값을 원소 뒤에 붙인다. queue = [(i, idx) for idx, i in enumerate(queue)] count = 0 while True: # queue안에 있는 원소 중 가장 큰 값이라면 if 실행 if queue[0][0] == max(queue, key=lambda x: x[0])[0]: count += 1 # 문제에서 찾길 원하는 원소인 경우 if queue[0][1] == m: print(count) break else: queue.pop(0) else: queue.append(queue.pop(0))
GitHub - DAWUNHAN/Algorithms-and-DataStructure: Algorithms and DataStructure with Python
Algorithms and DataStructure with Python. Contribute to DAWUNHAN/Algorithms-and-DataStructure development by creating an account on GitHub.
github.com
[ 패스트캠퍼스 알고리즘 / 기술면접 완전 정복 올인원 패키지 Online ] 강의 내용을 정리한 자료입니다.
'백준 Online Judge' 카테고리의 다른 글
[백준] 2110 공유기 문제 (0) 2021.09.27 [백준] 1543 - 문서 검색 (0) 2021.09.15 [1568] 새 (0) 2021.09.15 [백준] 1302 베스트셀러 (0) 2021.09.14 [백준] 1236 성 지키기 (0) 2021.09.14
