- Notifications
You must be signed in to change notification settings - Fork 846
/
Copy path3.py
19 lines (16 loc) · 676 Bytes
/
3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 현재 나이트의 위치 입력받기
input_data=input()
row=int(input_data[1])
column=int(ord(input_data[0])) -int(ord('a')) +1
# 나이트가 이동할 수 있는 8가지 방향 정의
steps= [(-2, -1), (-1, -2), (1, -2), (2, -1), (2, 1), (1, 2), (-1, 2), (-2, 1)]
# 8가지 방향에 대하여 각 위치로 이동이 가능한지 확인
result=0
forstepinsteps:
# 이동하고자 하는 위치 확인
next_row=row+step[0]
next_column=column+step[1]
# 해당 위치로 이동이 가능하다면 카운트 증가
ifnext_row>=1andnext_row<=8andnext_column>=1andnext_column<=8:
result+=1
print(result)