-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcavity-map.cpp
45 lines (36 loc) · 924 Bytes
/
cavity-map.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
// Cavity Map
// Depict cavities on a square map
//
// https://www.hackerrank.com/challenges/cavity-map/problem
//
#include <bits/stdc++.h>
using namespace std;
vector<string> cavityMap(size_t n, const vector<string>& grid) {
// Complete this function
vector<string> result = grid;
for (size_t i = 1; i < n - 1; ++i)
{
for (size_t j = 1; j < n - 1; ++j)
{
char v = grid[i][j];
if (v > grid[i - 1][j] && v > grid[i + 1][j] && v > grid[i][j - 1] && v > grid[i][j + 1])
{
result[i][j] = 'X';
}
}
}
return result;
}
int main() {
size_t n;
cin >> n;
vector<string> grid(n);
for (size_t grid_i = 0; grid_i < n; grid_i++) {
cin >> grid[grid_i];
}
vector<string> result = cavityMap(n, grid);
for (const auto& row : result) {
cout << row << endl;
}
return 0;
}