-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10828.py
More file actions
35 lines (27 loc) · 1.06 KB
/
10828.py
File metadata and controls
35 lines (27 loc) · 1.06 KB
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
31
32
33
34
35
import sys
input = sys.stdin.readline
n = int(input())
que = [] # 리스트로 스택 만듬
for i in range(n):
command = []
command = input().split() # 명령어 입력 받음
if command[0] == 'push': # push 일 때
que.append(int(command[1])) # 뒤에 스택의 맨위에 정수 저장
elif command[0] == 'pop': # pop 일 때
if len(que) == 0: # 비어있으면 -1 출력
print(-1)
else:
print(que[-1]) # 맨 위에 있는 정수 출력 후
del que[-1] # 맨 위에 있는 정수 제거
elif command[0] == 'top': # top 일 때
if len(que) == 0:
print(-1)
else:
print(que[-1]) # 맨 위에 있는 정수 출력
elif command[0] == 'size': # size 일 때
print(len(que)) # 스택의 크기 출력
elif command[0] == 'empty': # empty 일 때
if len(que) == 0: # 비어있으면 1 출력
print(1)
else: # 안 비어있으면 0 출력
print(0)