일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 프로그래머스
- 연관관계
- 그리디 알고리즘
- popleft
- LCM
- JPA
- 파이썬
- C#강의
- mvc
- Python
- 누적합
- 합 구하기
- 우선순위큐
- 소수찾기
- unity
- deque
- c#
- 백준
- Java
- 소수판별
- appendleft
- 1일1솔
- BFS
- 브루투포스
- 인프런
- python3
- pypy3
- spring
- 완전탐색
- DP
Archives
- Today
- Total
jae_coding
(백준 자료구조 문제풀이) 10828번 스택 본문
반응형
문제
코드
import sys
input = sys.stdin.readline
N = int(input())
stack = list()
def push(stack, num):
stack.append(num)
def pop(stack):
if len(stack) != 0:
n = stack[len(stack)-1]
print(n)
del stack[-1]
else:
print(-1)
def size(stack):
print(len(stack))
def empty(stack):
if len(stack) == 0:
print(1)
else:
print(0)
def top(stack):
if len(stack) != 0:
print(stack[len(stack)-1])
else:
print(-1)
for _ in range(N):
command = input().strip()
num = 0
if len(command) > 5:
command, num = command.split()
if command == "push":
push(stack, num)
elif command == "top":
top(stack)
elif command == "size":
size(stack)
elif command == "empty":
empty(stack)
elif command == "pop":
pop(stack)
반응형
'알고리즘 문제 > 자료구조 문제' 카테고리의 다른 글
(백준 자료구조 문제풀이) 1874번 스택 수열 (0) | 2022.07.19 |
---|---|
(백준 자료구조 문제풀이) 10866번 덱 (0) | 2022.07.18 |
(백준 자료구조 문제풀이) 1158번 요세푸스 문제 (0) | 2022.07.18 |
(백준 알고리즘 문제풀이) 18258번 큐 2 (0) | 2022.07.18 |
(백준 자료구조 문제풀이) 9012번 괄호 (0) | 2022.07.18 |
Comments