From 2fdb45e29f0ed7edc058bda3612b1804bbe68790 Mon Sep 17 00:00:00 2001 From: jaykxo Date: Wed, 22 Oct 2025 14:54:00 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Solved:=2028278=20=EC=8A=A4=ED=83=9D=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 0 bytes .../28278_\354\212\244\355\203\235_2.py" | 37 ++++++++++++++++++ 2 files changed, 37 insertions(+) delete mode 100644 .DS_Store create mode 100644 "jaykxo/week05/28278_\354\212\244\355\203\235_2.py" diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index a2e0dcb8782b546b2d7339c33f2cf95adc77488a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKT}s3-5T4Oh3cl>4k2!(`571re3F-l~uB^E2W)b{*>uo%WH}E`ulNn{>7JLvy zWTqtFWPXz7gC-p!;`#leB$^UYfhNeJjEI;=U3(UM0OT~s6UB$-Zr#Q8a%7^vXp(n7 zq+7bAXIfGI{@4?Ik93V^MJH5t%d)wO{bp+;nZJ*9-FC5szi401XK$ykv#)dXaq(@; z=4NM|ttDM`2AlzBz!`7`e#C&>Z;;|h(R*jW8E^(Z8IbcKpb1ungJL>5(4`UpIDt6{ zbg3mICm2?SgCaZ-)>NRTvXvOD>97Zjs|*K4O((YEgKg!H;)T=dm_MX&;!4qbXTTZA z8Q9n1RPO&Xd@`d&exBkZXTTZwXAJP9Zt6KUWq0e&_T;V&XcuTA5;uqffu8*YU?Atn fadN6Zh>p0*a8Q(4#GcZD{v(hG@y;3e1qR*$pp`I# diff --git "a/jaykxo/week05/28278_\354\212\244\355\203\235_2.py" "b/jaykxo/week05/28278_\354\212\244\355\203\235_2.py" new file mode 100644 index 0000000..5e312db --- /dev/null +++ "b/jaykxo/week05/28278_\354\212\244\355\203\235_2.py" @@ -0,0 +1,37 @@ +# 28278 스택 2 +# PyPy3, 메모리: 191116 KB, 시간: 372 ms +# Python3, 메모리: 74472 KB, 시간: 616 ms + +import sys +input = sys.stdin.readline + +N = int(input()) +stack = [] # 스택 저장 리스트 +result = [] # 출력 결과 저장 + +for _ in range(N): + cmd = input().split() + op = cmd[0] # 명령어 번호 (1~5) + + if op == '1': # push + x = int(cmd[1]) + stack.append(x) + elif op == '2': # pop, 비어있으면 -1 + if not stack: + result.append('-1') + else: + result.append(str(stack.pop())) + elif op == '3': # 현재 스택 크기 + result.append(str(len(stack))) + elif op == '4': # 비었으면 1, 아니면 0 + if not stack: + result.append('1') + else: + result.append('0') + elif op == '5': # 맨 위 원소, 없으면 -1 + if not stack: + result.append('-1') + else: + result.append(str(stack[-1])) + +print('\n'.join(result)) \ No newline at end of file From 88c3e91b79e971e42747a5cf9c922b77b41fe46a Mon Sep 17 00:00:00 2001 From: jaykxo Date: Wed, 22 Oct 2025 15:05:40 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Solved:=2018258=20=ED=81=90=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "jaykxo/week05/18258_\355\201\220_2.py" | 48 +++++++++++++++++++ .../28278_\354\212\244\355\203\235_2.py" | 4 ++ 2 files changed, 52 insertions(+) create mode 100644 "jaykxo/week05/18258_\355\201\220_2.py" diff --git "a/jaykxo/week05/18258_\355\201\220_2.py" "b/jaykxo/week05/18258_\355\201\220_2.py" new file mode 100644 index 0000000..8cc664d --- /dev/null +++ "b/jaykxo/week05/18258_\355\201\220_2.py" @@ -0,0 +1,48 @@ +# 18258 큐 2 +# PyPy3, 메모리: 225152 KB, 시간: 776 ms +# Python3, 메모리: 136696 KB, 시간: 1388 ms + +from collections import deque +import sys +input = sys.stdin.readline + +N = int(input()) +queue = deque() # 큐 저장용 덱 +result = [] # 출력 결과 저장 + +for _ in range(N): + cmd = input().split() + op = cmd[0] # 명령어 종류 (push, pop, size, empty, front, back) + + if op == 'push': # push: 큐에 값 추가 + X = int(cmd[1]) + queue.append(X) + + elif op == 'pop': # pop: 맨 앞 값 제거, 없으면 -1 + if not queue: + result.append('-1') + else: + result.append(str(queue.popleft())) # 메서드 한 줄만 써먹음,, + + elif op == 'size': # 큐 크기 출력 + result.append(str(len(queue))) + + elif op == 'empty': # 큐가 비었는지 여부 출력 + if not queue: + result.append('1') + else: + result.append('0') + + elif op == 'front': # 맨 앞 값 출력, 없으면 -1 + if not queue: + result.append('-1') + else: + result.append(str(queue[0])) + + elif op == 'back': # 맨 뒤 값 출력, 없으면 -1 + if not queue: + result.append('-1') + else: + result.append(str(queue[-1])) + +print('\n'.join(result)) \ No newline at end of file diff --git "a/jaykxo/week05/28278_\354\212\244\355\203\235_2.py" "b/jaykxo/week05/28278_\354\212\244\355\203\235_2.py" index 5e312db..6f952dd 100644 --- "a/jaykxo/week05/28278_\354\212\244\355\203\235_2.py" +++ "b/jaykxo/week05/28278_\354\212\244\355\203\235_2.py" @@ -16,18 +16,22 @@ if op == '1': # push x = int(cmd[1]) stack.append(x) + elif op == '2': # pop, 비어있으면 -1 if not stack: result.append('-1') else: result.append(str(stack.pop())) + elif op == '3': # 현재 스택 크기 result.append(str(len(stack))) + elif op == '4': # 비었으면 1, 아니면 0 if not stack: result.append('1') else: result.append('0') + elif op == '5': # 맨 위 원소, 없으면 -1 if not stack: result.append('-1') From 560d3fb55dd827fb3432334fd405cb724a96f3e4 Mon Sep 17 00:00:00 2001 From: jaykxo Date: Wed, 22 Oct 2025 15:19:39 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Solved:=2010773=20=EC=A0=9C=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../week05/10773_\354\240\234\353\241\234.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "jaykxo/week05/10773_\354\240\234\353\241\234.py" diff --git "a/jaykxo/week05/10773_\354\240\234\353\241\234.py" "b/jaykxo/week05/10773_\354\240\234\353\241\234.py" new file mode 100644 index 0000000..029b373 --- /dev/null +++ "b/jaykxo/week05/10773_\354\240\234\353\241\234.py" @@ -0,0 +1,19 @@ +# 10773 제로 +# PyPy3, 메모리: 114580 KB, 시간: 112 ms +# Python3, 메모리: 33192 KB, 시간: 68 ms + +import sys +input = sys.stdin.readline + +N = int(input()) +stack = [] # 숫자를 저장할 스택 + +for _ in range(N): + num = int(input()) + + if num != 0: # 0이 아니면 스택에 추가 + stack.append(num) + else: # 0이면 마지막 숫자 제거 + stack.pop() + +print(sum(stack)) # 남은 숫자들의 합 출력 \ No newline at end of file From 69479bb46f552047063b57875bce290190d10a40 Mon Sep 17 00:00:00 2001 From: jaykxo Date: Wed, 22 Oct 2025 15:29:59 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Solved:=202164=20=EC=B9=B4=EB=93=9C2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../week05/2164_\354\271\264\353\223\2342.py" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "jaykxo/week05/2164_\354\271\264\353\223\2342.py" diff --git "a/jaykxo/week05/2164_\354\271\264\353\223\2342.py" "b/jaykxo/week05/2164_\354\271\264\353\223\2342.py" new file mode 100644 index 0000000..36dadfd --- /dev/null +++ "b/jaykxo/week05/2164_\354\271\264\353\223\2342.py" @@ -0,0 +1,17 @@ +# 2164 카드2 +# PyPy3, 메모리: 117336 KB, 시간: 124 ms +# Python3, 메모리: 51848 KB, 시간: 164 ms + +from collections import deque +import sys +input = sys.stdin.readline + +N = int(input()) +q = deque(range(1, N+1)) # 1부터 N까지 카드 생성 + +# 카드가 한 장 남을 때까지 반복 +while len(q) > 1: + q.popleft() # 맨 위 카드 버림 + q.append(q.popleft()) # 다음 카드를 맨 아래로 이동 + +print(q[0]) # 마지막 남은 카드 출력 \ No newline at end of file