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
36 changes: 36 additions & 0 deletions cmkim/2021 카카오 인턴쉽/프로그래밍1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
num = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']

def solution(s):
answer = 0
count = 0
arr = []
i = 0
while i < len(s):
#print('i = ', i)

if s[i].isdigit():
arr.append(int(s[i]))

else:
j = 0
#print('i = ', i)
# print(s[i:])
while j < 10:
if num[j] in s[i:i+5]:
#print('num[j] =', num[j])
arr.append(j)
i += len(num[j]) - 1
break
j += 1
i += 1

#print(arr)
answer = int("".join(map(str, arr)))
#print('+'.join(arr))
#answer = int("".join(arr))
print(answer)
return answer

#solution("one4seveneight")
solution('1zerotwozero3')

54 changes: 54 additions & 0 deletions cmkim/2021 카카오 인턴쉽/프로그래밍2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from collections import deque

def solution(places):
answer = []

for i in range(5):
flag = 1
p_list = []
#p_ad_list = []
q = deque()

for x in range(5):
for y in range(5):
if places[i][x][y] == 'P':
p_list.append((x, y))

for a in range(len(p_list)):
for b in range(a+1, len(p_list)):
if abs(p_list[a][0] - p_list[b][0]) + abs(p_list[a][1] - p_list[b][1]) < 3:
q.append((p_list[a][0], p_list[a][1], p_list[b][0], p_list[b][1]))
#p_ad_list.append((p_list[a][0], p_list[a][1], p_list[b][0], p_list[b][1]))
#print('adjacent', p_list[a][0], p_list[a][1], p_list[b][0], p_list[b][1])

#2칸 아래,
#2칸 우측
#1칸 좌측, 1칸 아래
#1칸 우측, 1칸 아래

while q:
x1, y1, x2, y2 = q.popleft()
if x1 + 2 == x2:
if places[i][x1 + 1][y1] == 'O':
flag -= 1
elif y1 + 2 == y2:
if places[i][x1][y1+1] == 'O':
flag -= 1
elif y1 - 1 == y2 and x1 + 1 == x2: #왼쪽아래
if places[i][x1][y2] == 'O' or places[i][x2][y1] == 'O':
flag -= 1
elif y1 + 1 == y2 and x1 + 1 == x2:
if places[i][x1][y2] == 'O' or places[i][x2][y1] == 'O':
flag -= 1
elif x1 + 1 == x2 or y1 + 1 == y2:
flag -= 1


if flag > 0:
answer.append(1)
else:
answer.append(0)

return answer

print(solution([["POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"], ["POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"], ["PXOPX", "OXOXP", "OXPXX", "OXXXP", "POOXX"], ["OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"], ["PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"]]))
54 changes: 54 additions & 0 deletions cmkim/2021 카카오 인턴쉽/프로그래밍4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from collections import deque

#INF = 1000000000


def solution(n, start, end, roads, traps):
visited = [[0] * (n + 1) for _ in range(n+1)]
answer = 1000000
while q:
#print('roads = ', roads)
start, roads, traps, cost = q.popleft()

if start == end:
answer = min(answer, cost)
continue

for a, b, c in roads: # 출발, 도착, 비용
if start == a : # 이동할 다음노드가 있으면 이동
if b not in traps: #다음노드가 정상적으로 이동할 노드면
if not visited[a][b]:
visited[a][b] = 1
q.append((b, roads, traps, cost+c))
continue
else: # 다음노드가 함정노드면
if not visited[a][b]:
visited[a][b] = 1

for i in range(len(roads)):
if roads[i][0] == b or roads[i][1] == b:
temp = roads[i][0]
roads[i][0] = roads[i][1]
roads[i][1] = temp
q.append((b, roads, traps, cost+c))



print(answer)
return answer
q = deque()

# n = 3
# start = 1
# end = 3
# roads = [[1, 2, 2], [3, 2, 3]]
# traps = [2]

n = 4
start = 1
end = 4
roads = [[1, 2, 1], [3, 2, 1], [2, 4, 1]]
traps = [2, 3]

q.append((start, roads, traps, 0)) #마지막은 cost
solution(n, start, end, roads, traps)
29 changes: 29 additions & 0 deletions cmkim/2021 프로그래머스 써머코딩/프로그래밍1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys


# from collections import deque


def solution(code, day, data):
answer = []
q = []

for i in data:
arr = i.split(' ')
time = []
if code in arr[1]:
if day in arr[2]:
time.append(int(arr[2][5:13]))
time.append(int(arr[2][13:15]))

num = arr[0].split('=')
# answer.append(int(num[1]))
price = int(num[1])
q.append((time[1], time[0], price))

q.sort()

for i in range(len(q)):
answer.append(q[i][2])

return answer
35 changes: 35 additions & 0 deletions cmkim/2021 프로그래머스 써머코딩/프로그래밍2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from collections import deque


def solution(t, r):
q = []
wait = []
answer = []
flag = 0
for j in range(len(t)):
q.append((j, int(t[j]), int(r[j]))) # id, 나갈시간, 우선순위

for i in range(10000):
for j in range(len(q)):
if i == q[j][1]:
wait.append((q[j][0], q[j][2]))

index = 6
for k in range(len(wait)):
index = min(index, wait[k][1])

#print(wait)
for k in range(len(wait)):
if wait[k][1] == index:
pop_id = k
answer.append(wait[k][0])
wait.pop(pop_id)
break

flag = 0
print(answer)

return answer
t = [0,1,3,0]
r = [0,1,2,3]
solution(t, r)
Empty file.