Skip to content

Commit

Permalink
알고리즘
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyeongchoi committed Mar 3, 2021
1 parent dbf1db7 commit 8fcc390
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
40 changes: 40 additions & 0 deletions argorithm/2589.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
arr = [list(input().rstrip()) for _ in range(n)]
dx, dy = [-1, 1, 0, 0], [0, 0, -1, 1]
answer = []

def bfs(x, y):
q = deque()
q.append((x, y))
visited = [[-1]*m for _ in range(n)]
visited[x][y]=0
while q:
x, y = q.popleft()
for i in range(4):
sx, sy = x+dx[i], y+dy[i]
if not (0<=sx<n and 0<=sy<m):
continue
if arr[sx][sy]=='L' and visited[sx][sy]==-1:
visited[sx][sy] = visited[x][y]+1
q.append((sx, sy))
return max([max(val) for val in visited])


for a in range(n):
for b in range(m):
if arr[a][b]=='L':
if 0<=a-1 and a+1<n:
if arr[a-1][b]=='L' and arr[a+1][b]=='L':
continue
if 0<=b-1 and b+1<m:
if arr[a][b-1]=='L' and arr[a][b+1]=='L':
continue
answer.append(bfs(a, b))

print(max(answer))


38 changes: 38 additions & 0 deletions argorithm/new_id_recommend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
def solution(new_id):
answer = []
new_id = new_id.lower()
for i in new_id:
if i=='-' or i=='_' or i=='.' or i.isalnum():
answer.append(i)

try:
while True:
check = 0
if answer[0]=='.':
answer = answer[1:]
check = 1
if answer[-1]=='.':
answer = answer[:-1]
check = 1
for a in range(len(answer)-1):
if answer[a]=='.' and answer[a+1]=='.':
check = 1
answer = answer[:a]+answer[a+1:]
break
if not check:
break
except:
pass

if len(answer)==0:
answer = 'a'
if len(answer)>15:
answer = answer[:15]
if answer[-1]=='.':
answer = answer[:-1]
if len(answer)<3:
answer += answer[-1] * (3-len(answer))
return ''.join(answer)

if __name__ == '__main__':
print(solution("=.="))

0 comments on commit 8fcc390

Please sign in to comment.