forked from derekhh/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcavity-map.cpp
More file actions
45 lines (41 loc) · 797 Bytes
/
cavity-map.cpp
File metadata and controls
45 lines (41 loc) · 797 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
45
/*
cavity-map.cpp
Cavity Map
*/
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<vector<int> > v;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int main() {
int n;
cin >> n;
v.resize(n);
for (int i = 0; i < n; i++) {
string str;
cin >> str;
for (int j = 0; j < n; j++) {
v[i].push_back(str[j] - '0');
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int cnt = 0;
for (int k = 0; k < 4; k++) {
int ni = i + dx[k], nj = j + dy[k];
if (ni >= 0 && ni < n && nj >= 0 && nj < n && v[ni][nj] < v[i][j]) {
cnt++;
}
}
if (cnt == 4) {
cout << 'X';
} else {
cout << v[i][j];
}
}
cout << endl;
}
return 0;
}