We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e414c4a commit 1a86117Copy full SHA for 1a86117
learntosurf/Data Structures/2025-01-11-[BOJ]-#2164-카드2.py
@@ -1,12 +1,12 @@
1
import sys
2
-input = sys.stdin.read
+input = sys.stdin.readline
3
+from collections import deque
4
5
N = int(input())
-L = list(range(1,N+1))
6
+cards = deque(range(1, N + 1)) # 1부터 N까지의 숫자를 덱에 저장
7
-while (len(L)>1):
8
- L.pop(0)
9
- temp = L.pop(0)
10
- L.append(temp)
+while len(cards) > 1:
+ cards.popleft() # 제일 위의 카드를 버림
+ cards.append(cards.popleft()) # 그다음 카드를 아래로 옮김
11
12
-print(L.pop(0))
+print(cards[0]) # 마지막으로 남은 카드 출력
0 commit comments