t_왕실의나이트_115

source github.com/ndb796/python-for-coding-test
type 📌 개발노트
topics 600-알고리즘 & 코딩테스트 601 구현 & 완전탐색
types 문제풀이

문제

8 * 8 체스판
말형태로이동가능 가로세로 2,1 or 1,2
행 1-8 , 열 a-h
a1형태로 입력

8개의 경우의수가 있음 (기본적으로는)

import sys
# <span id="x-a-h"></span>x a-h
# <span id="y-1-8"></span>y 1-8
max = 8
input = sys.stdin.readline().strip()

x = ord(input[0])-ord('a')
y = int(input[1])-1
cnt = 0

way = [[1,2],[-1,2],[1,-2],[-1,-2],[2,1],[-2,1],[2,-1],[-2,-1]]
for tmx,tmy in way:
    tx = x+tmx
    ty = y+tmy
    if tx > -1 and ty > -1 and tx < max and ty< max:
        cnt+=1

print(cnt)