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
51 lines (43 loc) · 759 Bytes
/
cavity-map.cpp
File metadata and controls
51 lines (43 loc) · 759 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
46
47
48
49
50
51
//cavity-map.cpp
//Cavity Map
//101 Hack July'14
//Author: derekhh
#include<iostream>
#include<string>
using namespace std;
string map[110];
bool marked[110][110];
int dx[4] = { -1, 1, 0, 0 };
int dy[4] = { 0, 0, -1, 1 };
int n;
bool valid(int tx, int ty)
{
return 0 <= tx && tx < n && 0 <= ty && ty < n;
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> map[i];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
int val = map[i][j] - '0';
int cnt = 0;
for (int k = 0; k < 4; k++)
{
int ti = i + dx[k];
int tj = j + dy[k];
if (valid(ti, tj) && val > map[ti][tj] - '0')
cnt++;
}
if (cnt == 4)
cout << 'X';
else
cout << map[i][j];
if (j == n - 1)
cout << endl;
}
}
}