[BOJ] #2164번 카드 2
2022. 4. 25. 22:20ㆍ0️⃣ Algorithm&자료구조/BOJ
import time
import sys
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedQueue:
def __init__(self):
self.front = None
self.rear = None
self.size = 0
def push(self, data):
new_node = Node(data)
if self.isEmpty():
self.front = new_node
self.rear = new_node
else:
self.rear.next = new_node
self.rear = new_node
self.size += 1
def pop(self):
if self.isEmpty():
return -1
else:
dequeue_object = self.front
self.front = self.front.next
if self.front is None:
self.rear = None
self.size -= 1
return dequeue_object.data
def Size(self):
return self.size
def isEmpty(self):
is_Empty = False
if self.front is None:
is_Empty = True
else:
is_Empty = False
return is_Empty
queue = LinkedQueue()
def solution(n, queue):
for i in range(1, n+1):
queue.push(i)
while queue.Size() > 1:
num1 = queue.pop()
num = queue.pop()
queue.push(num)
return print(queue.pop())
import sys
n = int(sys.stdin.readline())
solution(n, queue)
'0️⃣ Algorithm&자료구조 > BOJ' 카테고리의 다른 글
[BOJ] # 2609번: 최대공약수와 최소공배수 (0) | 2022.05.02 |
---|---|
[BOJ] # 1037번: 약수 (0) | 2022.05.02 |
[BOJ] #18258번 큐 2 (0) | 2022.04.25 |
[BOJ] #10773 제로 (0) | 2022.04.25 |
[BOJ] #10828번 스택 (0) | 2022.04.25 |