Skip to content
Open
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
17 changes: 17 additions & 0 deletions Dongwon/kakao-intern/1_numString.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def solution(s):
result = s.lower()
num_dict = {
"zero": 0,
"one": 1,
"two": 2,
"three": 3,
"four": 4,
"five": 5,
"six": 6,
"seven": 7,
"eight": 8,
"nine": 9
}
for key, value in num_dict.items():
result = result.replace(key, str(value))
return int(result)
42 changes: 42 additions & 0 deletions Dongwon/kakao-intern/2_distancing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
def solution(places):
result = []
dx = [-2,-1,-1,-1,0,0,0,0,1,1,1,2]
dy = [0,-1,0,1,-2,-1,0,1,2,-1,0,1,0]
for place in places:
candiates = []
wall_checklist = []
for x in range(5):
for y in range(5):
cur_position = place[x][y]
if cur_position == "P": # 응시자 선출
candiates.append((x,y))
# 응시자들끼리 거리 비교
break_point = False
for i in range(len(candiates)):
for j in range(i+1, len(candiates)):
manhaton_x = candiates[i][0] - candiates[j][0]
manhaton_y = candiates[i][1] - candiates[j][1]
manhaton = abs(manhaton_x) + abs(manhaton_y)
# 맨하탄 거리가 2이하일때
if manhaton < 3:
if manhaton_x == 0: # x 값이 같을 때
if place[candiates[i][0]][(candiates[i][1] + candiates[j][1]) // 2] != "X":
result.append(0)
break_point = True
break
elif manhaton_y == 0: # y 값이 같을 때
if place[(candiates[i][0] + candiates[j][0]) // 2][candiates[i][1]] != "X":
result.append(0)
break_point = True
break
else:
# x,y 값이 다를 때
if place[candiates[i][0]][candiates[j][1]] != "X" or place[candiates[j][0]][candiates[i][1]] != "X":
result.append(0)
break_point = True
break
if break_point: # 하나라도 맞으면 나머지는 볼 필요 없음.
break
else: # 거리두기 잘 지키고 있을 때
result.append(1)
return result
92 changes: 92 additions & 0 deletions Dongwon/kakao-intern/3_editGraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
def solution (n,k,cmd):
selected = k
stack = []
board = [i+1 for i in range(n)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

board 사용하는 구간이 없는거 같습니다

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그렇네요ㅜㅜ 근데 저는 왜 안되는지가 궁금..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 테스트 3개만 통과해서 왜그런지 모르겠네요....

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋㅋㅋ 저도 정확도 테스트는 대여섯개는 맞아요 ㅜㅜ 어렵군.. 오늘 이놈이다!

arr = [1 for _ in range(n)]
for item in cmd:
# print(item)
# print(arr, selected, stack)
if len(item) == 3:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반례 찾아왔습니다 "U 14" 이런식으로도 들어올 수 있다고 하네요

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아아 맞네요!! >= 바꾸니깐 정확성 다 맞습니다 진현님 짱 😍

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

효율성 5개까지 맞네요 ㅎㅎ

direction, score = item.split(" ")
temp = 0
if direction == "U":
while temp < int(score) and selected >= 0:
selected -= 1
temp += arr[selected]
else:
while temp < int(score) and selected <= n-1:
selected += 1
temp += arr[selected]
else:
if item == "Z":
if stack:
garbage = stack.pop()
arr[garbage] = 1
else:
arr[selected] = 0
stack.append(selected)
if selected < n-1:
selected += 1
while arr[selected] == 0:
selected += 1
if arr[selected] != 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while문 어차피 탈출해서 따로 조건 안줘도 되지 않을까요?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 if문은 필요없긴하네유,,

break
else:
selected -= 1
while arr[selected] == 0:
selected -= 1
if arr[selected] != 0:
break
# 기본은 +1 증가인데 다음 노드가 없으면 다음으로 맨 마지막 노드이면 그전 노드로
return "".join(list(map(lambda x: "O" if x==1 else "X", arr)))


# 3차시도
# 유사 링크드 리스트 시도

def solution (n,k,cmd):
selected = k
stack = []
board = {}
for i in range(n):
board[i] = i

arr = [1 for _ in range(n)]

for item in cmd:
if len(item) == 3:
direction, score = item.split(" ")
if direction == "U":
temp = selected - int(score)
if temp < 0:
temp = 0
selected = board[temp]
else:
temp = selected + int(score)
if temp > n-1:
temp = n-1
selected = board[temp]
else:
if item == "Z":
if stack:
garbage = stack.pop()
arr[garbage] = 1
board[garbage] = garbage
else:
arr[selected] = 0
stack.append(selected)
if selected < n-1:
board[selected] = board[selected+1]
selected = board[selected]
# board[i] =
else:
board[selected] = board[selected-1]
selected = board[selected]
# for i in range(n):
# if board[i] == board[selected]:
# board[selected] = i
# print(i)
# selected = i
print(item)
print(board, selected, stack)
return "".join(list(map(lambda x: "O" if x==1 else "X", arr)))