Piyush and magic block problem

#include
using namespace std;
void magical_park(char a[][100],int m,int n,int k,int s)
{
bool success=true;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
char ch=a[i][j];
if(s<k){
success=false;
break;
}
if(ch==’*’)
{
s+=5;
}
else if(ch==’.’)
{
s-=2;
}
else
{
break;
}
if(j!=n-1)
{
s–;
}
}
}
if(success)
{
cout<<“Yes”<<endl;
cout<<s<<endl;
}
else
{
cout<<“No”<<endl;
}
}
int main() {
int m,n,k,s;
cin>>m>>n>>k>>s;
char park[100][100];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>park[i][i];
}
}
magical_park(park,m,n,k,s);
return 0;
}

// it is not passing 100% cases
//it is giving only 60% correct results

hi @devyanshbansal123
refer this code -->

@devyanshbansal123
I hope it’s clear now??

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

pls tell me where was mistake in my code

Save ur code on coding Blocks ide and send link…

here it is

hi @devyanshbansal123
sry for delayed reply… i was debugging ur code… found a very sill mistake in ur code
cin>>park[i][i];
here u have written i instead of j in cin…
it should be park[i][j]
corrected code -->


It’s passing all test cases now…

@devyanshbansal123
Is there anything else?? Or shall I mark the doubt as resolved??

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.