Skip to content

Commit e5914d6

Browse files
committed
[BOJ] 카드 2 / 실버4 / 15분
1 parent 3c6501a commit e5914d6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

JYP/카드 2.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 마지막 남은 카드 번호 구하는 문제
2+
# 가장 먼저 카드의 개수를 불러온 뒤, deque함수를 이용해 빈 큐를 생성한다
3+
import sys
4+
from collections import deque
5+
6+
a = int(sys.stdin.readline())
7+
deq = deque()
8+
9+
# 이후, for문을 통해 1부터 a까지의 수(카드 번호)를 큐에 넣는다
10+
for i in range(a):
11+
deq.append(i+1)
12+
# while문을 통해 deq가 1이 될 때까지 가장 위 차드를 버리고, 제일 위 카드를 가장 아래로 옮긴다
13+
while len(deq) > 1:
14+
deq.popleft()
15+
deq.append(deq.popleft())
16+
17+
print(deq.pop())

0 commit comments

Comments
 (0)