Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions algorithms/data_structure/hwangon/10828.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys

n = int(sys.stdin.readline())

stack = []
for i in range(n):
command = sys.stdin.readline().split()

if command[0] == 'push':
stack.append(command[1])

elif command[0] == 'pop':
if len(stack)==0:
print(-1)
else:
print(stack.pop())

elif command[0] == 'size':
print(len(stack))

elif command[0] == 'empty':
if len(stack)==0:
print(1)
else:
print(0)

elif command[0] == 'top':
if len(stack)==0:
print(-1)
else:
print(stack[-1])
39 changes: 39 additions & 0 deletions algorithms/data_structure/hwangon/18258.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
from collections import deque

q = deque()
N = int(sys.stdin.readline())

for _ in range(N) :
command = sys.stdin.readline().split()

if command[0] == 'push' :
q.append(int(command[1]))

elif command[0] == 'pop' :
if not q :
print (-1)
else :
print(q[0])
q.popleft()

elif command[0] == 'size' :
print(len(q))

elif command[0] == 'empty' :
if len(q) == 0 :
print(1)
else :
print(0)

elif command[0] == 'front' :
if not q:
print(-1)
else :
print(q[0])

elif command[0] == 'back' :
if not q :
print(-1)
else :
print(q[-1])
11 changes: 11 additions & 0 deletions algorithms/data_structure/hwangon/2164.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from collections import deque

n = int(input())
cards = deque(range(1, n + 1))

while len(cards) > 1:
cards.popleft()
cards.append(cards[0])
cards.popleft()

print(cards[0])
22 changes: 22 additions & 0 deletions algorithms/data_structure/hwangon/2800.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from itertools import combinations

expr = list(input())
indices = []
stack = []
answers = set()

for i in range(len(expr)):
if expr[i] == '(':
stack.append(i)
elif expr[i] == ')':
indices.append((stack.pop(), i))

for i in range(len(indices)):
for comb in combinations(indices, i + 1):
temp = expr[:]
for idx in comb:
temp[idx[0]] = temp[idx[1]] = ""
answers.add("".join(temp))

for item in sorted(list(answers)):
print(item)
24 changes: 24 additions & 0 deletions algorithms/data_structure/hwangon/9012.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
n = int(input())

brackets = []
for _ in range(n):
brackets.append(input())

for bracket in brackets:
stack = []
bracket_len = len(bracket)
cnt = 0
for b in bracket:
if b == "(":
stack.append("(")
else:
if stack:
stack.pop()
else:
break
cnt += 1

if not stack and cnt == bracket_len:
print('YES')
else:
print('NO')