# Hackerrank Cavity Map Solution

The Solution for hackerrank problem, Cavity Map using C++ Program.
Passed Test cases: 21 out of 21

### SOURCE CODE:

`````` #include<iostream>
using namespace std;
int main(){
int n,i,j;
cin>>n;
string inp[n];
for(i=0;i<n;i++)
{
cin>>inp[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i == 0 || j == 0 || i == n-1 || j == n-1 )
{
cout<<inp[i][j];
}
else if(inp[i][j] > inp[i][j-1] && inp[i][j] > inp[i][j+1] && inp[i][j] >inp[i-1][j] && inp[i][j] > inp[i+1][j])
{
cout<<"X" ;
}
else
{
cout<<inp[i][j];
}
}
cout<<endl;
}
return 0;
}
``````

1. I'm impressed. You're truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. I'm saving this for future use.

Rica
www.imarksweb.org

2. inp is 1d , but how you are using it as a 2d array?

1. input is an array of strings,
so it is also similar to an 2D array of characters.

http://www.hellgeeks.com/array-of-strings/

3. I have done it by 2-d array but its showing wrong. I have run it in my compiler DEV C++ and its running fine

1. Can you share the code here?

4. in php plz

5. //whats wrong with this?
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main(){

int n,i,j;
char b,c,d;
cin >> n;
char a[100][100];

for(i=0;i> a[i];

for(i=0;id))
cout << "x";
else
cout << a[i][j];
}
if(i!=n-1)
cout << endl;
}

return 0;
}

6. Life is full of many challenges. Challenges that will make you or break you depending on how you handle it. Visit my site for more updates. God Bless to your site.

n8fan.net

www.n8fan.net