Skip to content

Commit 2d2fa22

Browse files
authored
주말코테 (#74)
1 parent f1b6448 commit 2d2fa22

File tree

6 files changed

+208
-0
lines changed

6 files changed

+208
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
num = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
2+
3+
def solution(s):
4+
answer = 0
5+
count = 0
6+
arr = []
7+
i = 0
8+
while i < len(s):
9+
#print('i = ', i)
10+
11+
if s[i].isdigit():
12+
arr.append(int(s[i]))
13+
14+
else:
15+
j = 0
16+
#print('i = ', i)
17+
# print(s[i:])
18+
while j < 10:
19+
if num[j] in s[i:i+5]:
20+
#print('num[j] =', num[j])
21+
arr.append(j)
22+
i += len(num[j]) - 1
23+
break
24+
j += 1
25+
i += 1
26+
27+
#print(arr)
28+
answer = int("".join(map(str, arr)))
29+
#print('+'.join(arr))
30+
#answer = int("".join(arr))
31+
print(answer)
32+
return answer
33+
34+
#solution("one4seveneight")
35+
solution('1zerotwozero3')
36+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from collections import deque
2+
3+
def solution(places):
4+
answer = []
5+
6+
for i in range(5):
7+
flag = 1
8+
p_list = []
9+
#p_ad_list = []
10+
q = deque()
11+
12+
for x in range(5):
13+
for y in range(5):
14+
if places[i][x][y] == 'P':
15+
p_list.append((x, y))
16+
17+
for a in range(len(p_list)):
18+
for b in range(a+1, len(p_list)):
19+
if abs(p_list[a][0] - p_list[b][0]) + abs(p_list[a][1] - p_list[b][1]) < 3:
20+
q.append((p_list[a][0], p_list[a][1], p_list[b][0], p_list[b][1]))
21+
#p_ad_list.append((p_list[a][0], p_list[a][1], p_list[b][0], p_list[b][1]))
22+
#print('adjacent', p_list[a][0], p_list[a][1], p_list[b][0], p_list[b][1])
23+
24+
#2칸 아래,
25+
#2칸 우측
26+
#1칸 좌측, 1칸 아래
27+
#1칸 우측, 1칸 아래
28+
29+
while q:
30+
x1, y1, x2, y2 = q.popleft()
31+
if x1 + 2 == x2:
32+
if places[i][x1 + 1][y1] == 'O':
33+
flag -= 1
34+
elif y1 + 2 == y2:
35+
if places[i][x1][y1+1] == 'O':
36+
flag -= 1
37+
elif y1 - 1 == y2 and x1 + 1 == x2: #왼쪽아래
38+
if places[i][x1][y2] == 'O' or places[i][x2][y1] == 'O':
39+
flag -= 1
40+
elif y1 + 1 == y2 and x1 + 1 == x2:
41+
if places[i][x1][y2] == 'O' or places[i][x2][y1] == 'O':
42+
flag -= 1
43+
elif x1 + 1 == x2 or y1 + 1 == y2:
44+
flag -= 1
45+
46+
47+
if flag > 0:
48+
answer.append(1)
49+
else:
50+
answer.append(0)
51+
52+
return answer
53+
54+
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"]]))
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from collections import deque
2+
3+
#INF = 1000000000
4+
5+
6+
def solution(n, start, end, roads, traps):
7+
visited = [[0] * (n + 1) for _ in range(n+1)]
8+
answer = 1000000
9+
while q:
10+
#print('roads = ', roads)
11+
start, roads, traps, cost = q.popleft()
12+
13+
if start == end:
14+
answer = min(answer, cost)
15+
continue
16+
17+
for a, b, c in roads: # 출발, 도착, 비용
18+
if start == a : # 이동할 다음노드가 있으면 이동
19+
if b not in traps: #다음노드가 정상적으로 이동할 노드면
20+
if not visited[a][b]:
21+
visited[a][b] = 1
22+
q.append((b, roads, traps, cost+c))
23+
continue
24+
else: # 다음노드가 함정노드면
25+
if not visited[a][b]:
26+
visited[a][b] = 1
27+
28+
for i in range(len(roads)):
29+
if roads[i][0] == b or roads[i][1] == b:
30+
temp = roads[i][0]
31+
roads[i][0] = roads[i][1]
32+
roads[i][1] = temp
33+
q.append((b, roads, traps, cost+c))
34+
35+
36+
37+
print(answer)
38+
return answer
39+
q = deque()
40+
41+
# n = 3
42+
# start = 1
43+
# end = 3
44+
# roads = [[1, 2, 2], [3, 2, 3]]
45+
# traps = [2]
46+
47+
n = 4
48+
start = 1
49+
end = 4
50+
roads = [[1, 2, 1], [3, 2, 1], [2, 4, 1]]
51+
traps = [2, 3]
52+
53+
q.append((start, roads, traps, 0)) #마지막은 cost
54+
solution(n, start, end, roads, traps)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
3+
4+
# from collections import deque
5+
6+
7+
def solution(code, day, data):
8+
answer = []
9+
q = []
10+
11+
for i in data:
12+
arr = i.split(' ')
13+
time = []
14+
if code in arr[1]:
15+
if day in arr[2]:
16+
time.append(int(arr[2][5:13]))
17+
time.append(int(arr[2][13:15]))
18+
19+
num = arr[0].split('=')
20+
# answer.append(int(num[1]))
21+
price = int(num[1])
22+
q.append((time[1], time[0], price))
23+
24+
q.sort()
25+
26+
for i in range(len(q)):
27+
answer.append(q[i][2])
28+
29+
return answer
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from collections import deque
2+
3+
4+
def solution(t, r):
5+
q = []
6+
wait = []
7+
answer = []
8+
flag = 0
9+
for j in range(len(t)):
10+
q.append((j, int(t[j]), int(r[j]))) # id, 나갈시간, 우선순위
11+
12+
for i in range(10000):
13+
for j in range(len(q)):
14+
if i == q[j][1]:
15+
wait.append((q[j][0], q[j][2]))
16+
17+
index = 6
18+
for k in range(len(wait)):
19+
index = min(index, wait[k][1])
20+
21+
#print(wait)
22+
for k in range(len(wait)):
23+
if wait[k][1] == index:
24+
pop_id = k
25+
answer.append(wait[k][0])
26+
wait.pop(pop_id)
27+
break
28+
29+
flag = 0
30+
print(answer)
31+
32+
return answer
33+
t = [0,1,3,0]
34+
r = [0,1,2,3]
35+
solution(t, r)

cmkim/2021 프로그래머스 써머코딩/프로그래밍3.py

Whitespace-only changes.

0 commit comments

Comments
 (0)