Piyush and Magical Park

#include
using namespace std;
void magical_park(char a[][100], int n, int m, int k,int s) {

    bool success = true;

int i,j;
for(int i =0;i<n;i++){
for(int j =0;j<m;j++){
char ch = a[i][j];
if(s<k){
success = false;
}
if(ch==’*’){
s+=5;
}
if(ch ==’.’)
s-=2;
else
break;
if(j!=n-1){
s–;
}

		}

	}
	if(success)
{
cout<<"Yes"<<endl;
	cout<<s<<endl;
}
else
cout<<"No";

}

int main(){
int n,m,k,s;
cin>>n>>m>>k>>s;
int i,j;

char park[100][100];
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++){
            cin>>park[i][j];
    }}


	magical_park(park,n,m,k,s);

return 0;
}


shift

outside the j for loop

thank u so much Maam. It worked.

1 Like

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.