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
- HTML
- KDT
- ํ๋ก๊ทธ๋๋จธ์ค
- ์ฝ๋ฉ์ ํ
- ํ๋ก ํธ์๋
- ๊ฐ๋ฐ
- JS
- Python
- ๋ ธ๋ง๋์ฝ๋
- react
- ๋ชจ๊ฐ์ฝ
- javascript
- Til
- ์ฝ๋ฉํ ์คํธ
- ํ ์ดํ๋ก์ ํธ
- fe
- ํ๋ก์ ํธ
- CSS
- mongodb
- error
- node.js
- ์๊ณ ๋ฆฌ์ฆ
- heapq
- ์ฝ๋ฉ
- ํ์ด์ฌ
- ํฌ๋กค๋ง
- ๊ทธ๋ฆฌ๋
- ๋๋ฆผ์ฝ๋ฉ
- ๊ตญ๋น์ง์
- ๋ฐฑ์ค
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 |