forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3.cpp
More file actions
31 lines (25 loc) Β· 867 Bytes
/
3.cpp
File metadata and controls
31 lines (25 loc) Β· 867 Bytes
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
#include <bits/stdc++.h>
using namespace std;
string inputData;
// λμ΄νΈκ° μ΄λν μ μλ 8κ°μ§ λ°©ν₯ μ μ
int dx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};
int main(void) {
// νμ¬ λμ΄νΈμ μμΉ μ
λ ₯λ°κΈ°
cin >> inputData;
int row = inputData[1] - '0';
int column = inputData[0] - 'a' + 1;
// 8κ°μ§ λ°©ν₯μ λνμ¬ κ° μμΉλ‘ μ΄λμ΄ κ°λ₯νμ§ νμΈ
int result = 0;
for (int i = 0; i < 8; i++) {
// μ΄λνκ³ μ νλ μμΉ νμΈ
int nextRow = row + dx[i];
int nextColumn = column + dy[i];
// ν΄λΉ μμΉλ‘ μ΄λμ΄ κ°λ₯νλ€λ©΄ μΉ΄μ΄νΈ μ¦κ°
if (nextRow >= 1 && nextRow <= 8 && nextColumn >= 1 && nextColumn <= 8) {
result += 1;
}
}
cout << result << '\n';
return 0;
}