-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.py
More file actions
53 lines (45 loc) Β· 1.51 KB
/
3.py
File metadata and controls
53 lines (45 loc) Β· 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# λμ νμ΄
count = 0
data = input()
row = data[0]
col = int(data[1])
operation = [[2, -1], [2, 1], [1, 2], [1, -2]]
row_data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
rowIndex = 0
for item in row_data:
if(row == item):
break
rowIndex += 1
for i in range(8):
tempRowIndex = rowIndex
tempColIndex = col
if(i < 4):
tempRowIndex += operation[i][0]
tempColIndex += operation[i][1]
else:
tempRowIndex += operation[i % 4][0] * -1
tempColIndex += operation[i % 4][1] * -1
if(tempRowIndex < 0 or tempRowIndex > 8 or tempColIndex < 1 or tempColIndex > 8):
continue
count += 1
print(count)
# λλλΉλ νμ΄
# νμ¬ λμ΄νΈμ μμΉ μ
λ ₯λ°κΈ°
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
for step in steps:
# μ΄λνκ³ μ νλ μμΉ νμΈ
next_row = row + step[0]
next_column = column + step[1]
# ν΄λΉ μμΉλ‘ μ΄λμ΄ κ°λ₯νλ€λ©΄ μΉ΄μ΄νΈ μ¦κ°
if next_row >= 1 and next_row <= 8 and next_column >= 1 and next_column <= 8:
result += 1
print(result)
# μνλ²³μ μ
λ ₯λ°λ κ²½μ° ordν¨μλ₯Ό μ΄μ©ν΄ λ°νλλ asciiκ° μ΄μ©νκΈ°
# λ°©ν₯μ°μ°μ νλ κ²½μ° μ’ν κ° νλ²μ λνκΈ° ex(2, -1)