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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions 2week/1929-소수 구하기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
M,N = map(int,input().split())
for i in range(M,N+1): #9
if i ==1:
continue
for j in range(2,i): #2345678
if i % j == 0: #9/2
break
else:
print(i)
10 changes: 10 additions & 0 deletions 2week/1978-소수 찾기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
num = input()
M,N = map(int,input().split())
for i in range(M,N+1): #9
if i ==1:
continue
for j in range(2,i): #2345678
if i % j == 0: #9/2
break
else:
print(len(i))
24 changes: 24 additions & 0 deletions 3week/10280-스택.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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)
11 changes: 11 additions & 0 deletions 3week/10773-제로.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cnt = int(input())
list = []
for i in range(cnt):
num = int(input())
if num == 0 :
list.pop()
else:
list.append(num)


print(sum(list))
30 changes: 30 additions & 0 deletions 3week/10845-큐.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys

N = int(sys.stdin.readline())

queue = []

for i in range(N):
cmd = sys.stdin.readline().split()

if cmd[0] == "push":
queue.insert(0, cmd[1])

elif cmd[0] == "pop":
if len(queue) != 0: print(queue.pop())
else: print(-1)

elif cmd[0] == "size":
print(len(queue))

elif cmd[0] == "empty":
if len(queue) == 0: print(1)
else : print(0)

elif cmd[0] == "front":
if len(queue) == 0: print(-1)
else: print(queue[len(queue) -1])

elif cmd[0] == "back":
if len(queue) == 0: print(-1)
else: print(queue[0])
26 changes: 26 additions & 0 deletions 3week/10866-덱.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys
input = sys.stdin.readline

n = int(input())

cmd = [input() for _ in range(n)]

deque = []

for c in cmd:
if 'push_front' in c.split()[0]:
deque.insert(0, c.split()[1])
elif 'push_back' in c.split()[0]:
deque.append(c.split()[1])
elif 'pop_front' in c:
print(deque.pop(0)) if deque else print(-1)
elif 'pop_back' in c:
print(deque.pop(-1)) if deque else print(-1)
elif 'size' in c:
print(len(deque))
elif 'empty' in c:
print(0) if deque else print(1)
elif 'front' in c:
print(deque[0]) if deque else print(-1)
elif 'back' in c:
print(deque[-1]) if deque else print(-1)
17 changes: 17 additions & 0 deletions 3week/11866-요세푸스 문제0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
from collections import deque
n, k = map(int, sys.stdin.readline().split())
d=deque()
res=[]
for i in range(1, n+1):
d.append(i)
while len(d)!=0:
for _ in range(k-1):
d.append(d.popleft())
res.append(d.popleft())
print('<', end='')
for i in range(len(res)):
if i==len(res)-1:
print(res[i],end='>')
else:
print(res[i], end=', ')
30 changes: 30 additions & 0 deletions 3week/18258-큐2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys

N = int(sys.stdin.readline())

queue = []

for i in range(N):
cmd = sys.stdin.readline().split()

if cmd[0] == "push":
queue.insert(0, cmd[1])

elif cmd[0] == "pop":
if len(queue) != 0: print(queue.pop())
else: print(-1)

elif cmd[0] == "size":
print(len(queue))

elif cmd[0] == "empty":
if len(queue) == 0: print(1)
else : print(0)

elif cmd[0] == "front":
if len(queue) == 0: print(-1)
else: print(queue[len(queue) -1])

elif cmd[0] == "back":
if len(queue) == 0: print(-1)
else: print(queue[0])
14 changes: 14 additions & 0 deletions 3week/2164-카드2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
nums = int(input())
card = []
ans = []

for i in range(1, nums+1):
card.append(i)

while (len(card) != 0):
ans.append(card.pop(0))
if(len(card) != 0):
card.append(card.pop(0))

for j in ans:
print(j, end =" ")
19 changes: 19 additions & 0 deletions 3week/9012-괄호.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
T = int(input())

for i in range(T):
stack = []
a=input()
for j in a:
if j == '(':
stack.append(j)
elif j == ')':
if stack:
stack.pop()
else:
print("NO")
break
else:
if not stack:
print("YES")
else:
print("NO")