Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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
- ๋๋ฆผ์ฝ๋ฉ
- ๊ฐ๋ฐ
- ํ ์ดํ๋ก์ ํธ
- ์ฝ๋ฉ์ ํ
- heapq
- ์ฝ๋ฉ
- Python
- ๋ฐฑ์ค
- ์๊ณ ๋ฆฌ์ฆ
- react
- node.js
- ๋ ธ๋ง๋์ฝ๋
- ํ๋ก๊ทธ๋๋จธ์ค
- ๊ทธ๋ฆฌ๋
- HTML
- mongodb
- CSS
- ํ๋ก์ ํธ
- ๊ตญ๋น์ง์
- ๋ชจ๊ฐ์ฝ
- javascript
- error
- ํฌ๋กค๋ง
- ํ์ด์ฌ
- ํ๋ก ํธ์๋
- KDT
- JS
- fe
- ์ฝ๋ฉํ ์คํธ
- Til
Archives
- Today
- Total
๐ฑ → ๐ณ
[๋ฐฑ์ค] 10828๋ฒ: ์คํ - python ๋ณธ๋ฌธ
728x90
https://www.acmicpc.net/problem/10828
stack class๋ฅผ ์ ์ํ์ฌ stack์ ๊ธฐ๋ฅ/๋ช ๋ น์ ๊ตฌํํจ
sys๋ฅผ ์ฐ์ง ์์ผ๋ ์๊ฐ์ด๊ณผ๊ฐ ๋ฌ์ import sys๋ก ์๊ฐ์ด๊ณผ ํด๊ฒฐ
์ ๋ต์ฝ๋:
import sys
input = sys.stdin.readline
class Stack:
def __init__(self):
self.data=[]
def empty(self):
if len(self.data) == 0:
return 1
else:
return 0
def size(self):
return len(self.data)
def push(self, X):
self.data.append(X)
def pop(self):
if self.size() == 0:
return -1
else:
return self.data.pop()
def top(self):
if self.size() == 0:
return -1
else:
return self.data[-1]
num = int(input())
stack = Stack()
for _ in range(num):
cmd = input().split()
op = cmd[0]
if op == 'push':
stack.push(cmd[1])
elif op == 'empty':
print(stack.empty())
elif op == 'pop':
print(stack.pop())
elif op == 'size':
print(stack.size())
elif op == 'top':
print(stack.top())
else:
print('err')
728x90
'Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 9012๋ฒ: ๊ดํธ python (0) | 2023.01.03 |
---|---|
[๋ฐฑ์ค] 9093๋ฒ: ๋จ์ด ๋ค์ง๊ธฐ python (0) | 2023.01.02 |
[๋ฐฑ์ค] 11729๋ฒ: ํ๋ ธ์ด์ ํ ์ด๋ ์์ - python (0) | 2022.12.30 |
[๋ฐฑ์ค] 25501๋ฒ: ์ฌ๊ท์ ๊ท์ฌ python (0) | 2022.11.16 |
Algorithm) Dynamic Programming (1) | 2022.10.25 |