Algorithm/Implement
[μ΄μ½ν ]ꡬν/μμ€μ λμ΄νΈ/μ€μ λ¬Έμ
μ νΈλ
2024. 10. 9. 15:06
π λ¬Έμ
πμ€νκ²°κ³Ό
μ λ ₯ : a1
μΆλ ₯ : 2
π λ΄κ° μκ°ν νμ΄
π» λ΄ μ½λ
# μμ€μ λμ΄νΈ
# μμ νμλ¬Έμ
# 2μ°¨μ λ°°μ΄ νΉμ 리μ€νΈλ‘ ꡬν κ°λ₯
# μμΉ μ
λ ₯ λ°κΈ°, a1
n = input()
# νμ μμ€ν€μ½λλ‘ λ³νν n첫λ²μ§Έ κ°μμ aμμ€ν€μ½λλ‘ λ³ν μ + 1?
column = int(ord(n[0])) - int(ord('a'))+1
# μ΄μ μμΉ μ
λ ₯μ λλ²μ§Έ μ
row = int(n[1])
# λμ΄νΈκ° μ΄λνλ κ²½μ°μ μ 8κ°μ§
step = [(2,-1),(-1,2),(1,-2),(-2,1),(1,2),(2,1),(-1,-2),(-2,-1)]
result = 0
for i in step:
next_column = column + i[0]
next_row = row + i[1]
# 8*8λ°°μ΄ μμ μμ λλ§ result+1
if next_column <= 8 and next_column >= 1 and next_row <= 8 and next_row >=1:
result += 1
# μ΄ resultμ ν©
print(result)