-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0040.cpp
More file actions
43 lines (39 loc) · 1.01 KB
/
Copy pathE0040.cpp
File metadata and controls
43 lines (39 loc) · 1.01 KB
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
/*
Problem Statement: https://www.hackerrank.com/challenges/cavity-map/problem
*/
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string> cavityMap(vector<string> grid) {
for(int i=1 ; i<grid.size()-1 ; i++){
for(int j=1 ; j<grid[i].length()-1 ; j++){
int cur_depth = int(grid[i][j]) - '0';
int top_depth = int(grid[i-1][j]) - '0';
int bottom_depth = int(grid[i+1][j]) - '0';
int left_depth = int(grid[i][j-1]) - '0';
int right_depth = int(grid[i][j+1]) - '0';
if(top_depth == 40 || bottom_depth == 40 || left_depth == 40 || right_depth == 40)
continue;
else if(top_depth < cur_depth && bottom_depth < cur_depth && left_depth < cur_depth && right_depth < cur_depth)
grid[i][j] = 'X';
}
}
return grid;
}
int main()
{
int n;
string s;
vector<string> map, results;
cin>>n;
cin.ignore();
for(int i=0 ; i<n ; i++){
getline(cin, s);
map.push_back(s);
}
results = cavityMap(map);
for(int i=0 ; i<results.size() ; i++)
cout<<results[i]<<endl;
return 0;
}