The Solution for hackerrank problem, Cavity Map using C++ Program.
Passed Test cases: 21 out of 21
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;
}
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.
ReplyDeleteRica
www.imarksweb.org
inp is 1d , but how you are using it as a 2d array?
ReplyDeleteinput is an array of strings,
Deleteso it is also similar to an 2D array of characters.
Useful links :
http://www.hellgeeks.com/array-of-strings/
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
ReplyDeleteCan you share the code here?
Deletein php plz
ReplyDeletesure :)
Delete//whats wrong with this?
ReplyDelete#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;
}
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.
ReplyDeleten8fan.net
www.n8fan.net