From bb8b2553decb308751cb5dbffdf92e7183384b2c Mon Sep 17 00:00:00 2001 From: HwanGonJang Date: Sat, 31 May 2025 13:24:00 +0900 Subject: [PATCH] feat: week1 --- algorithms/data_structure/hwangon/10828.py | 31 +++++++++++++++++ algorithms/data_structure/hwangon/18258.py | 39 ++++++++++++++++++++++ algorithms/data_structure/hwangon/2164.py | 11 ++++++ algorithms/data_structure/hwangon/2800.py | 22 ++++++++++++ algorithms/data_structure/hwangon/9012.py | 24 +++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 algorithms/data_structure/hwangon/10828.py create mode 100644 algorithms/data_structure/hwangon/18258.py create mode 100644 algorithms/data_structure/hwangon/2164.py create mode 100644 algorithms/data_structure/hwangon/2800.py create mode 100644 algorithms/data_structure/hwangon/9012.py diff --git a/algorithms/data_structure/hwangon/10828.py b/algorithms/data_structure/hwangon/10828.py new file mode 100644 index 0000000..816f550 --- /dev/null +++ b/algorithms/data_structure/hwangon/10828.py @@ -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]) \ No newline at end of file diff --git a/algorithms/data_structure/hwangon/18258.py b/algorithms/data_structure/hwangon/18258.py new file mode 100644 index 0000000..8b1301d --- /dev/null +++ b/algorithms/data_structure/hwangon/18258.py @@ -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]) \ No newline at end of file diff --git a/algorithms/data_structure/hwangon/2164.py b/algorithms/data_structure/hwangon/2164.py new file mode 100644 index 0000000..e938977 --- /dev/null +++ b/algorithms/data_structure/hwangon/2164.py @@ -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]) \ No newline at end of file diff --git a/algorithms/data_structure/hwangon/2800.py b/algorithms/data_structure/hwangon/2800.py new file mode 100644 index 0000000..e1c1e3b --- /dev/null +++ b/algorithms/data_structure/hwangon/2800.py @@ -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) \ No newline at end of file diff --git a/algorithms/data_structure/hwangon/9012.py b/algorithms/data_structure/hwangon/9012.py new file mode 100644 index 0000000..ea9b138 --- /dev/null +++ b/algorithms/data_structure/hwangon/9012.py @@ -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') \ No newline at end of file