[문제]
https://www.acmicpc.net/problem/10828
[풀이]
2021.07.26 - [BOJ] - [Python] BOJ/백준 10845번 큐
[코드]
import sys
class stack():
def __init__(self):
self.stack = []
self.size = 0
def push(self, x):
self.stack.append(x)
self.size += 1
def pop(self):
if self.size == 0:
return -1
else:
self.size -= 1
return self.stack.pop()
def my_size(self):
return self.size
def empty(self):
if self.size == 0:
return 1
else:
return 0
def top(self):
if self.size == 0:
return -1
else:
return self.stack[-1]
if __name__ == '__main__':
stack = stack()
n = int(sys.stdin.readline())
for _ in range(n):
command = sys.stdin.readline().split()
if command[0] == 'push':
stack.push(command[1])
elif command[0] == 'pop':
sys.stdout.write(str(stack.pop()))
sys.stdout.write("\n")
elif command[0] == 'size':
sys.stdout.write(str(stack.my_size()))
sys.stdout.write("\n")
elif command[0] == 'empty':
sys.stdout.write(str(stack.empty()))
sys.stdout.write("\n")
elif command[0] == 'top':
sys.stdout.write(str(stack.top()))
sys.stdout.write("\n")
'문제풀이 > BOJ' 카테고리의 다른 글
[Python] BOJ/백준 2798번 블랙잭 (0) | 2021.07.28 |
---|---|
[Python] BOJ/백준 1018번 체스판 다시 칠하기 (0) | 2021.07.26 |
[Python] BOJ/백준 10866번 덱 (0) | 2021.07.26 |
[Python] BOJ/백준 10845번 큐 (0) | 2021.07.26 |
[Python] BOJ/백준 2751번 수 정렬하기 2 (0) | 2021.07.24 |