王室の夜
5921 ワード
質問する
8つの8座標平面があります.一室にナイトクラブが立っている.ナイト移動時はL字でしか移動できません.チェスしかできません.nightは、次の2つの状況に移動できます.
8 x 8平面において、あるノードの位置が与えられた場合、そのノードが移動可能な数が出力される.行位置は1〜8、列位置はa〜hで表す.
例
ナイトがa 1にいた時
ナイトがc 2にいた時
に道を教える
計算:[(-2, 1), (-2, -1), (2, 1), (2, -1), (1, 2), (-1, 2), (1, -2), (-1, -2)]
input_data = input()
column = int(ord(input_data[0])) - int(ord('a')) + 1
row = int(input_data[1])
steps = [(-2, 1), (-2, -1), (2, 1), (2, -1), (1, 2), (-1, 2), (1, -2), (-1, -2)]
result = 0
for step in steps:
next_column = column + step[0]
next_row = row + step[1]
if (next_column >= 1) and (next_column <= 8) and (next_row >= 1) and (next_column <= 8):
result += 1
print(result)
Reference
この問題について(王室の夜), 我々は、より多くの情報をここで見つけました
https://velog.io/@dana/구현-왕실의-나이트
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
input_data = input()
column = int(ord(input_data[0])) - int(ord('a')) + 1
row = int(input_data[1])
steps = [(-2, 1), (-2, -1), (2, 1), (2, -1), (1, 2), (-1, 2), (1, -2), (-1, -2)]
result = 0
for step in steps:
next_column = column + step[0]
next_row = row + step[1]
if (next_column >= 1) and (next_column <= 8) and (next_row >= 1) and (next_column <= 8):
result += 1
print(result)
Reference
この問題について(王室の夜), 我々は、より多くの情報をここで見つけました https://velog.io/@dana/구현-왕실의-나이트テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol