Algorithm/COS
[COS Pro 1급, Python] 6차 9번 : 스택으로 큐 만들기
JMcunst
2022. 3. 1. 12:16
728x90
문제 유형
빈칸
난이도
easy
Note
1.func_a : stack에서 값을 꺼냄.(pop)
func_b : stack1에서 pop해서 stack2에 넣는 함수.
func_c : stack이 비었는지 체크하는 함수.
Code
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
def func_a(stack):
return stack.pop()
def func_b(stack1, stack2):
while not func_c(stack1):
item = func_a(stack1)
stack2.append(item)
def func_c(stack):
return (len(stack) == 0)
def solution(stack1, stack2):
if func_c(stack2):
func_b(stack1, stack2)
answer = func_a(stack2)
return answer
stack1_1 = [1,2]
stack2_1 = [3,4]
ret1 = solution(stack1_1, stack2_1)
print("solution 함수의 반환 값은", ret1, "입니다.")
stack1_2 = [1,2,3]
stack2_2 = []
ret2 = solution(stack1_2, stack2_2)
print("solution 함수의 반환 값은", ret2, "입니다.")
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
※ 반례가 있으면 알려주시면 감사하겠습니다.
728x90