FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
timus_cpp/task_1197.cpp at master · artbataev/timus_cpp · GitHub
artbataev
/
timus_cpp
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
timus_cpp
/
task_1197.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (43 loc) · 1.12 KB
Breadcrumbs
timus_cpp
/
task_1197.cpp
Copy path
File metadata and controls
53 lines (43 loc) · 1.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
;
}
Back
|
FazBrowse Home
|
New Git URL