일기 대신 코드 슬쩍

6. 구현(왕실의 나이트) 본문

Python/알고리즘(Python)

6. 구현(왕실의 나이트)

코코자 2023. 3. 2. 13:23

<문제> 왕실의 나이트

# 왕실의 나이트
location = 'a1'
x = 0
y = 0
# 열을 숫자로 변경해주기
if location[0] == 'a':
    x = 1
elif location[0] == 'b':
    x = 2
elif location[0] == 'c':
    x = 3
elif location[0] == 'd':
    x = 4
elif location[0] == 'e':
    x = 4
elif location[0] == 'f':
    x = 3
elif location[0] == 'g':
    x = 2
elif location[0] == 'h':
    x = 1


if int(location[1]) > 4:
    if location[1] == '5':
        y = 4
    elif location[1] == '6':
        y = 3
    elif location[1] == '7':
        y = 2
    elif location[1] == '8':
        y = 1
else:
    y = int(location[1])


count = 0
# 경우 나눠서 계산
if x > 2 and y > 2:
    count += 8
elif x == 2 and y > 2:
    count += 6
elif x > 2 and y == 2:
    count += 6
elif x == 1 and y > 2:
    count += 4
elif x > 2  and y == 1:
    count += 4
elif x == 1 and y == 2:
    count += 3
elif x == 2 and y == 1:
    count += 3
elif x == 1 and y == 1:
    count += 2

print(count)

<문제> 게임 개발

# 게임 개발
visit = 0
end = 0
# 크기, 장소, 방향, 지형 차례로 입력받기
n, m = map(int, input().split())
x,y,me = map(int, input().split())
if n < 3:
    n = 3
if m > 50:
    m = 50
map = [[0] * n for i in range(m)]
for i in range(m):
    mmap = list(map(int,input().split()))
    map[i] = mmap[:n]

풀다가 어려워서 다른사람 참고하려고 들어갔는데 안 풀어도 되는 문제였나봐요

어려우니까 실력 키우고 다시 오겠습니다.