-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_1197.cpp
53 lines (43 loc) · 1.12 KB
/
task_1197.cpp
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
#include <iostream>
#include <vector>
struct Position {
int row;
int col;
Position(int row_, int col_): row(row_), col(col_) {};
bool is_correct() {
return row >= 1 && row <= 8 && col >= 1 && col <= 8;
}
};
Position operator+(const Position& lhs, const Position& rhs) {
return {lhs.row + rhs.row, lhs.col + rhs.col};
}
const std::vector<Position> MOVES = {
{2, 1},
{2, -1},
{-2, 1},
{-2, -1},
{1, 2},
{1, -2},
{-1, 2},
{-1, -2},
};
bool can_attack(Position current_position, Position offset) {
Position new_position = current_position + offset;
return new_position.is_correct();
}
int main() {
int n;
std::cin >> n;
char col_char;
Position current_position {0, 0};
for (int i = 0; i < n; i++) {
std::cin >> col_char >> current_position.row;
current_position.col = col_char - 'a' + 1;
int num_attacked = 0;
for (auto offset:MOVES) {
num_attacked += can_attack(current_position, offset);
}
std::cout << num_attacked << std::endl;
}
return 0;
}