-
Notifications
You must be signed in to change notification settings - Fork 1
/
CavityMap.cpp
47 lines (32 loc) · 904 Bytes
/
CavityMap.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
46
47
// problem: "https://www.hackerrank.com/challenges/cavity-map/problem"
#include<iostream>
using namespace std;
int main()
{
long int n,i,j;
char A[100][100];
cin>>n;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>A[i][j];
for(i=1;i<n-1;i++)
for(j=1;j<n-1;j++)
{
if((A[i][j]<=A[i-1][j])||(A[i-1][j]=='X'))
continue;
if((A[i][j]<=A[i][j-1])||(A[i][j-1]=='X'))
continue;
if((A[i][j]<=A[i+1][j])||(A[i+1][j]=='X'))
continue;
if((A[i][j]<=A[i][j+1])||(A[i][j+1]=='X'))
continue;
A[i][j]='X';
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cout<<A[i][j];
cout<<endl;
}
return 0;
}