-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-3.cpp
More file actions
44 lines (37 loc) · 946 Bytes
/
4-3.cpp
File metadata and controls
44 lines (37 loc) · 946 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
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @file 4-3.cpp
* @brief 왕실의 나이트
* @author Sam Kim (samkim2626@gmail.com)
*/
#include <iostream>
#include <utility>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string s;
getline(cin, s);
int row = s[1] - '0';
int column = s[0] - 'a' + 1;
pair<int, int> moves[8] = {{1, -2},
{-1, -2},
{-2, -1},
{-2, 1},
{1, 2},
{-1, 2},
{2, 1},
{2, -1}};
int cnt = 0;
for (int i = 0; i < 8; i++)
{
int nextR = row + moves[i].first;
int nextC = column + moves[i].second;
if (nextR >= 1 && nextR <= 8 && nextC >= 1 && nextC <= 8)
{
cnt++;
}
}
cout << cnt << '\n';
return 0;
}