๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐‘†๐‘ข๐‘›๐‘ โ„Ž๐‘–๐‘›๐‘’ ๐‘Ž๐‘“๐‘ก๐‘’๐‘Ÿ ๐‘Ÿ๐‘Ž๐‘–๐‘›โœง

[Python] ๋ฐฑ์ค€ 14923 ๋ฏธ๋กœํƒˆ์ถœ & ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ ๋ณธ๋ฌธ

๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ด๐Ÿ’ป/[๐๐ฒ๐ญ๐ก๐จ๐ง] ๐€๐ฅ๐ ๐จ๐ซ๐ข๐ญ๐ก๐ฆ

[Python] ๋ฐฑ์ค€ 14923 ๋ฏธ๋กœํƒˆ์ถœ & ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ

๐ŸคRyusun๐Ÿค 2023. 9. 17. 13:29

๋ฐฑ์ค€ 14923

# ๋ฐฑ์ค€ 14923 ๋ฏธ๋กœํƒˆ์ถœ

from collections import deque
n, m = map(int, input().split())
Hx, Hy = map(int, input().split())
Ex, Ey = map(int, input().split())
graph = [list(map(int, input().split())) for _ in range(n)]
visited = [[[0] * 2 for _ in range(m)] for _ in range(n)]

d_row = [0, -1, 0, 1]
d_col = [1, 0, -1, 0]

def solution(Hx, Hy):
    queue = deque()
    x, y = Hx-1, Hy-1
    queue.append([x,y, 0])
    visited[x][y][0] = 0
    while queue:
        x, y, w = queue.popleft()
        if x == Ex-1 and y == Ey-1:
            return visited[x][y][w]
        for i in range(4):
            nx = d_row[i] + x
            ny = d_col[i] + y
            if 0<= nx < n and 0 <= ny < m :
                if graph[nx][ny] == 0 and visited[nx][ny][w]==0: # ๋‹ค์Œ๋…ธ๋“œ๊ฐ€ 0์ด๊ณ  ์•„์ง ๋ฐฉ๋ฌธ์•ˆํ–ˆ๋‹ค๋ฉด
                    queue.append([nx,ny,w])
                    visited[nx][ny][w] = visited[x][y][w]+1
                elif graph[nx][ny] == 1 and w == 0: # ๋‹ค์Œ ๋…ธ๋“œ๊ฐ€ 1(๋ฒฝ)์ด๊ณ  ๊ทธ ๋ฒฝ์„ ์•ˆ ๋ถ€์‹  ์ƒํƒœ๋ผ๋ฉด
                    visited[nx][ny][w+1] = visited[x][y][w] + 1
                    queue.append([nx, ny, w+1])

    else:
        return -1

print(solution(Hx, Hy))


 

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ

 

๋‚ด ์ฝ”๋“œ

def solution(s):
    s = s.lower()
    new_list = []
    str_list = s.split(" ")
    for i in str_list:
        if not i[0:1].isdigit():
            a = i[0:1].upper()
            i = "".join([a, i[1:]])
        new_list.append(i)

    return " ".format(" ".join(new_list))

solution("3people unFollowed me")

 

๋” ์‰ฌ์šด ์ฝ”๋“œ

def solution2(s):
    return ' '.join([word.capitalize() for word in s.split(" ")])

solution2("3people unFollowed me")

 

ํ•จ์ˆ˜ .capitalize()๋ฅผ ์“ฐ๋ฉด ํ•œ๋ฐฉ์— ํ•ด๊ฒฐ๋œ๋‹ค...ใ…Ž