| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- Java
- BFS
- 그리디 알고리즘
- 프로그래머스
- spring
- 인프런
- pypy3
- Python
- 파이썬
- 1일1솔
- 누적합
- C#강의
- appendleft
- deque
- LCM
- popleft
- 소수찾기
- mvc
- 연관관계
- unity
- DP
- 우선순위큐
- 소수판별
- c#
- 완전탐색
- 백준
- 브루투포스
- 합 구하기
- JPA
- python3
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