Skip to content
Merged
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
Binary file removed .DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions jaykxo/week05/10773_제로.py
Original file line number Diff line number Diff line change
@@ -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)) # 남은 숫자들의 합 출력
48 changes: 48 additions & 0 deletions jaykxo/week05/18258_큐_2.py
Original file line number Diff line number Diff line change
@@ -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))
17 changes: 17 additions & 0 deletions jaykxo/week05/2164_카드2.py
Original file line number Diff line number Diff line change
@@ -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]) # 마지막 남은 카드 출력
41 changes: 41 additions & 0 deletions jaykxo/week05/28278_스택_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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))