From bb1a8ddd43203bc013ce8a75f79a512db1384930 Mon Sep 17 00:00:00 2001 From: sminy85 Date: Mon, 2 Sep 2024 11:07:25 +0900 Subject: [PATCH 1/2] delete file --- saemi/week_4/boj_10866.py | 42 --------------------------------------- saemi/week_4/boj_11279.py | 21 -------------------- saemi/week_4/boj_1874.py | 29 --------------------------- saemi/week_4/boj_2075.py | 14 ------------- saemi/week_4/boj_4949.py | 30 ---------------------------- saemi/week_4/boj_5397.py | 24 ---------------------- 6 files changed, 160 deletions(-) delete mode 100644 saemi/week_4/boj_10866.py delete mode 100644 saemi/week_4/boj_11279.py delete mode 100644 saemi/week_4/boj_1874.py delete mode 100644 saemi/week_4/boj_2075.py delete mode 100644 saemi/week_4/boj_4949.py delete mode 100644 saemi/week_4/boj_5397.py diff --git a/saemi/week_4/boj_10866.py b/saemi/week_4/boj_10866.py deleted file mode 100644 index d2337dc..0000000 --- a/saemi/week_4/boj_10866.py +++ /dev/null @@ -1,42 +0,0 @@ -import sys -from collections import deque - -N = sys.stdin.readline().rstrip() -dq = deque() - -for _ in range(int(N)): - command = sys.stdin.readline().split() - - if command[0] == 'push_front': #X: 정수 X를 덱의 앞에 넣는다. - dq.appendleft(command[1]) - elif command[0] == 'push_back': #X: 정수 X를 덱의 뒤에 넣는다. - dq.append(command[1]) - elif command[0] == 'pop_front': #덱의 가장 앞에 있는 수를 빼고, 그 수를 출력한다. 만약, 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. - if len(dq) == 0: - print(-1) - else: - print(dq[0]) - dq.popleft() - elif command[0] == 'pop_back': #덱의 가장 뒤에 있는 수를 빼고, 그 수를 출력한다. 만약, 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. - if len(dq) == 0: - print(-1) - else: - print(dq[len(dq) - 1]) - dq.pop() - elif command[0] == 'size': #덱에 들어있는 정수의 개수를 출력한다. - print(len(dq)) - elif command[0] == 'empty': #덱이 비어있으면 1을, 아니면 0을 출력한다. - if len(dq) == 0: - print(1) - else: - print(0) - elif command[0] == 'front': #덱의 가장 앞에 있는 정수를 출력한다. 만약 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. - if len(dq) == 0: - print(-1) - else: - print(dq[0]) - elif command[0] == 'back': #덱의 가장 뒤에 있는 정수를 출력한다. 만약 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. - if len(dq) == 0: - print(-1) - else: - print(dq[len(dq) - 1]) diff --git a/saemi/week_4/boj_11279.py b/saemi/week_4/boj_11279.py deleted file mode 100644 index 6a47c52..0000000 --- a/saemi/week_4/boj_11279.py +++ /dev/null @@ -1,21 +0,0 @@ -import sys -input = sys.stdin.readline -import heapq - -N = int(input()) -q = [] -answer = [] -count = 0 - -for index in range(N): - n = int(input()) - if n == 0: - count += 1 - if q == []: - answer.append(0) - else: - answer.append(-heapq.heappop(q)) - else: - heapq.heappush(q, -n) - -[print(answer[i]) for i in range(count)] \ No newline at end of file diff --git a/saemi/week_4/boj_1874.py b/saemi/week_4/boj_1874.py deleted file mode 100644 index b04979b..0000000 --- a/saemi/week_4/boj_1874.py +++ /dev/null @@ -1,29 +0,0 @@ -count = 1 -temp = True -stack = [] -op = [] - -N = int(input()) -for i in range(N): - num = int(input()) - # num이하 숫자까지 스택에 넣기 - while count <= num: - stack.append(count) - op.append('+') - count += 1 - - # num이랑 스택 맨 위 숫자가 동일하다면 제거 - if stack[-1] == num: - stack.pop() - op.append('-') - # 스택 수열을 만들 수 없으므로 NO - else: - temp = False - break - -# 스택 수열을 만들수 있는지 여부에 따라 출력 -if temp == False: - print("NO") -else: - for i in op: - print(i) \ No newline at end of file diff --git a/saemi/week_4/boj_2075.py b/saemi/week_4/boj_2075.py deleted file mode 100644 index 8f8baa9..0000000 --- a/saemi/week_4/boj_2075.py +++ /dev/null @@ -1,14 +0,0 @@ -import sys -input = sys.stdin.readline -import heapq - -N = int(input()) -q = [] - -for _ in range(N): - for n in map(int, input().split()): - heapq.heappush(q, n) - q = heapq.nlargest(N, q) - -heapq.heapify(q) -print(heapq.heappop(q)) \ No newline at end of file diff --git a/saemi/week_4/boj_4949.py b/saemi/week_4/boj_4949.py deleted file mode 100644 index 41e1a16..0000000 --- a/saemi/week_4/boj_4949.py +++ /dev/null @@ -1,30 +0,0 @@ -answer = [] - -while True : - text = input() - stack = [] - - if text == "." : - break - - for item in text : - if item == '[' or item == '(' : - stack.append(item) - elif item == ']' : - if len(stack) != 0 and stack[-1] == '[' : - stack.pop() - else : - stack.append(item) - break - elif item == ')' : - if len(stack) != 0 and stack[-1] == '(' : - stack.pop() - else : - stack.append(item) - break - if len(stack) == 0 : - answer.append('yes') - else : - answer.append('no') - -print(*answer, sep='\n') \ No newline at end of file diff --git a/saemi/week_4/boj_5397.py b/saemi/week_4/boj_5397.py deleted file mode 100644 index ddfb235..0000000 --- a/saemi/week_4/boj_5397.py +++ /dev/null @@ -1,24 +0,0 @@ -N = int(input()) - -answer = [] -for _ in range(N): - leftPass = [] - rightPass = [] - text = input() - for item in text: - if item == '-': - if leftPass: #왼쪽 스택에 있을 경우 - leftPass.pop() - elif item == '<': # 왼스택에 있는 문자 오른쪽 스택으로 - if leftPass: - rightPass.append(leftPass.pop()) - elif item == '>': # 오스택에 있는 문자 왼쪽 스택으로 - if rightPass: - leftPass.append(rightPass.pop()) - else: - leftPass.append(item) - - leftPass.extend(reversed(rightPass)) # 오른쪽 스택에 있는 문자들은 뒤집어서 붙여야 한다. - answer.append(''.join(leftPass)) - -print(*answer, sep='\n') \ No newline at end of file From ff35b38c937ae6869e15cee9dcf2eef52cf8a878 Mon Sep 17 00:00:00 2001 From: sminy85 Date: Mon, 2 Sep 2024 11:10:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=204=EC=A3=BC=EC=B0=A8=20stack&queue?= =?UTF-8?q?=20=EB=AC=B8=EC=A0=9C=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- saemi/week_4/boj_10866.py | 42 +++++++++++++++++++++++++++++++++++++++ saemi/week_4/boj_11279.py | 21 ++++++++++++++++++++ saemi/week_4/boj_1874.py | 29 +++++++++++++++++++++++++++ saemi/week_4/boj_2075.py | 14 +++++++++++++ saemi/week_4/boj_4949.py | 30 ++++++++++++++++++++++++++++ saemi/week_4/boj_5397.py | 24 ++++++++++++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 saemi/week_4/boj_10866.py create mode 100644 saemi/week_4/boj_11279.py create mode 100644 saemi/week_4/boj_1874.py create mode 100644 saemi/week_4/boj_2075.py create mode 100644 saemi/week_4/boj_4949.py create mode 100644 saemi/week_4/boj_5397.py diff --git a/saemi/week_4/boj_10866.py b/saemi/week_4/boj_10866.py new file mode 100644 index 0000000..d2337dc --- /dev/null +++ b/saemi/week_4/boj_10866.py @@ -0,0 +1,42 @@ +import sys +from collections import deque + +N = sys.stdin.readline().rstrip() +dq = deque() + +for _ in range(int(N)): + command = sys.stdin.readline().split() + + if command[0] == 'push_front': #X: 정수 X를 덱의 앞에 넣는다. + dq.appendleft(command[1]) + elif command[0] == 'push_back': #X: 정수 X를 덱의 뒤에 넣는다. + dq.append(command[1]) + elif command[0] == 'pop_front': #덱의 가장 앞에 있는 수를 빼고, 그 수를 출력한다. 만약, 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. + if len(dq) == 0: + print(-1) + else: + print(dq[0]) + dq.popleft() + elif command[0] == 'pop_back': #덱의 가장 뒤에 있는 수를 빼고, 그 수를 출력한다. 만약, 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. + if len(dq) == 0: + print(-1) + else: + print(dq[len(dq) - 1]) + dq.pop() + elif command[0] == 'size': #덱에 들어있는 정수의 개수를 출력한다. + print(len(dq)) + elif command[0] == 'empty': #덱이 비어있으면 1을, 아니면 0을 출력한다. + if len(dq) == 0: + print(1) + else: + print(0) + elif command[0] == 'front': #덱의 가장 앞에 있는 정수를 출력한다. 만약 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. + if len(dq) == 0: + print(-1) + else: + print(dq[0]) + elif command[0] == 'back': #덱의 가장 뒤에 있는 정수를 출력한다. 만약 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. + if len(dq) == 0: + print(-1) + else: + print(dq[len(dq) - 1]) diff --git a/saemi/week_4/boj_11279.py b/saemi/week_4/boj_11279.py new file mode 100644 index 0000000..6a47c52 --- /dev/null +++ b/saemi/week_4/boj_11279.py @@ -0,0 +1,21 @@ +import sys +input = sys.stdin.readline +import heapq + +N = int(input()) +q = [] +answer = [] +count = 0 + +for index in range(N): + n = int(input()) + if n == 0: + count += 1 + if q == []: + answer.append(0) + else: + answer.append(-heapq.heappop(q)) + else: + heapq.heappush(q, -n) + +[print(answer[i]) for i in range(count)] \ No newline at end of file diff --git a/saemi/week_4/boj_1874.py b/saemi/week_4/boj_1874.py new file mode 100644 index 0000000..b04979b --- /dev/null +++ b/saemi/week_4/boj_1874.py @@ -0,0 +1,29 @@ +count = 1 +temp = True +stack = [] +op = [] + +N = int(input()) +for i in range(N): + num = int(input()) + # num이하 숫자까지 스택에 넣기 + while count <= num: + stack.append(count) + op.append('+') + count += 1 + + # num이랑 스택 맨 위 숫자가 동일하다면 제거 + if stack[-1] == num: + stack.pop() + op.append('-') + # 스택 수열을 만들 수 없으므로 NO + else: + temp = False + break + +# 스택 수열을 만들수 있는지 여부에 따라 출력 +if temp == False: + print("NO") +else: + for i in op: + print(i) \ No newline at end of file diff --git a/saemi/week_4/boj_2075.py b/saemi/week_4/boj_2075.py new file mode 100644 index 0000000..8f8baa9 --- /dev/null +++ b/saemi/week_4/boj_2075.py @@ -0,0 +1,14 @@ +import sys +input = sys.stdin.readline +import heapq + +N = int(input()) +q = [] + +for _ in range(N): + for n in map(int, input().split()): + heapq.heappush(q, n) + q = heapq.nlargest(N, q) + +heapq.heapify(q) +print(heapq.heappop(q)) \ No newline at end of file diff --git a/saemi/week_4/boj_4949.py b/saemi/week_4/boj_4949.py new file mode 100644 index 0000000..41e1a16 --- /dev/null +++ b/saemi/week_4/boj_4949.py @@ -0,0 +1,30 @@ +answer = [] + +while True : + text = input() + stack = [] + + if text == "." : + break + + for item in text : + if item == '[' or item == '(' : + stack.append(item) + elif item == ']' : + if len(stack) != 0 and stack[-1] == '[' : + stack.pop() + else : + stack.append(item) + break + elif item == ')' : + if len(stack) != 0 and stack[-1] == '(' : + stack.pop() + else : + stack.append(item) + break + if len(stack) == 0 : + answer.append('yes') + else : + answer.append('no') + +print(*answer, sep='\n') \ No newline at end of file diff --git a/saemi/week_4/boj_5397.py b/saemi/week_4/boj_5397.py new file mode 100644 index 0000000..ddfb235 --- /dev/null +++ b/saemi/week_4/boj_5397.py @@ -0,0 +1,24 @@ +N = int(input()) + +answer = [] +for _ in range(N): + leftPass = [] + rightPass = [] + text = input() + for item in text: + if item == '-': + if leftPass: #왼쪽 스택에 있을 경우 + leftPass.pop() + elif item == '<': # 왼스택에 있는 문자 오른쪽 스택으로 + if leftPass: + rightPass.append(leftPass.pop()) + elif item == '>': # 오스택에 있는 문자 왼쪽 스택으로 + if rightPass: + leftPass.append(rightPass.pop()) + else: + leftPass.append(item) + + leftPass.extend(reversed(rightPass)) # 오른쪽 스택에 있는 문자들은 뒤집어서 붙여야 한다. + answer.append(''.join(leftPass)) + +print(*answer, sep='\n') \ No newline at end of file