diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index a2e0dcb..0000000 Binary files a/.DS_Store and /dev/null differ 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 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/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 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..6f952dd --- /dev/null +++ "b/jaykxo/week05/28278_\354\212\244\355\203\235_2.py" @@ -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)) \ No newline at end of file