-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathCavity Map.cpp
More file actions
38 lines (31 loc) · 869 Bytes
/
Cavity Map.cpp
File metadata and controls
38 lines (31 loc) · 869 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
#include <iostream>
#include <vector>
using namespace std;
int dx[] = { 0, 0, 1, -1 };
int dy[] = { 1, -1, 0, 0 };
int main(){
int n;
cin >> n;
vector<string> grid(n);
for(int i = 0; i < n; i++)
cin >> grid[i];
int nx, ny;
bool f;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
f = true;
for(int k = 0; k < 4; k++) {
nx = i + dx[k];
ny = j + dy[k];
if(!(nx < n && nx >= 0 && ny < n && ny >= 0 && grid[nx][ny] != 'X' && grid[nx][ny] < grid[i][j])) {
f = false;
break;
}
}
if(f) grid[i][j] = 'X';
}
}
for(int i = 0; i < n; i++)
cout << grid[i] << endl;
return 0;
}