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
35 changes: 35 additions & 0 deletions 구현/BOJ_1283_단축키지정_밀리.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
n = int(input())
keys = []
options = []
completed = [False] * n
for i in range(n):
options.append(list(map(str, input().split())))

for i in range(n):
# 1단계
for j in range(len(options[i])):
if options[i][j][0].lower() in keys:
continue
else:
keys.append(options[i][j][0].lower())
options[i][j] = '[' + options[i][j][0] + ']' + options[i][j][1:]
completed[i] = True
break
# 2단계
for j in range(len(options[i])):
if completed[i] == True:
break
for h in range(len(options[i][j])):
if options[i][j][h].lower() in keys:
continue
else:
keys.append(options[i][j][h].lower())
options[i][j] = options[i][j][:h] + '[' + options[i][j][h] + ']' + options[i][j][h+1:]
completed[i] = True
break

for i in range(n):
for j in options[i]:
print(j, end=" ")
print()

47 changes: 47 additions & 0 deletions 이진탐색/BOJ_2615_오목_밀리.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
def findWinner():
board = []
for i in range(19):
board.append(list(map(int, input().split())))

# 동북, 동, 동남, 남
dx = [-1, 0, 1, 1]
dy = [1, 1, 1, 0]

for x in range(19):
for y in range(19):
if board[x][y] == 0:
continue
current = board[x][y]
# 총 4 방향에 대해서 확인
for i in range(4):
flag = 0
nx, ny = x, y
# 바둑알의 색이 현재 위치에서 총 5개까지 일치하는지 확인
for _ in range(4):
nx = nx + dx[i]
ny = ny + dy[i]
if nx < 0 or nx >= 19 or ny < 0 or ny >= 19:
flag = 1
break
if board[nx][ny] != current:
flag = 1
break
# 다음 6번째 알이 일치하면 이긴 것이 아님
nx = nx + dx[i]
ny = ny + dy[i]
if 0 <= nx < 19 and 0 <= ny < 19:
if board[nx][ny] == current:
flag = 1
# 이전 알이 일치하면 이긴 것이 아님
nx = x - dx[i]
ny = y - dy[i]
if 0 <= nx < 19 and 0 <= ny < 19:
if board[nx][ny] == current:
flag = 1
if flag == 0:
print(current)
print(x+1, y+1)
return
print(0)

findWinner()