-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBEE-2419.cpp
More file actions
44 lines (34 loc) · 888 Bytes
/
Copy pathBEE-2419.cpp
File metadata and controls
44 lines (34 loc) · 888 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
#include <iostream>
#include <vector>
int main()
{
int m {};
int n {};
std::cin >> m >> n;
int terrn = m * n;
std::vector<int> map(terrn);
std::vector<int> landCoords;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
char territory {};
std::cin >> territory;
if (territory == '.') continue;
int idx = i * n + j;
map[idx] = 1;
landCoords.push_back(idx);
}
}
int coastn {};
for (int idx : landCoords) {
int i = (int) idx / n;
int j = idx % n;
if (i == 0 || i == m - 1 ||
j == 0 || j == n - 1 ||
map[idx - n] == 0 || map[idx + n] == 0 ||
map[idx - 1] == 0 || map[idx + 1] == 0) {
coastn++;
}
}
std::cout << coastn << "\n";
return 0;
}