Discussion About Piyush and Magical Park

This is Discussion thread about Piyush and Magical Park

can any one help me in solving this https://hack.codingblocks.com/app/practice/6/p/55 problem

If there are M columns in a row, does that means there are M number of steps to be taken if there is no # in the row?
Or whenever we move to new row counts as step?
I am not getting this line:
Also while moving in a row, Piyush requires strength of 1 for every step and strength should always be positive for moving forward.

Atleast give an explaination of the test case or explain the question correctly.

The output doesn’t make any sense without an explanation. What does “exiting the park” means? If it means to get to the right most point, The first line fetches a total strength of 15, it should be the answer? How did 13 come? A simple explanation of the solution would answer many doubts.

public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int N=s.nextInt();
int M=s.nextInt();
int K=s.nextInt();
int S=s.nextInt();
char[][] arr=new char[N][M];
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
arr[i][j]=s.next().charAt(0);
}
}
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
if(arr[i][j]==’.’)
{
S=S-2;
if(j!=(M-1))
{
S=S-1;
}
}
if(arr[i][j]==’*’)
{
S=S+5;
if(j!=(M-1))
{
S=S-1;
}
}
if(arr[i][j]==’#’)
{
break;
}
}

	   }
	   if(S>K)
	   {
		   System.out.println("Yes");
		   System.out.println(S);
	   }
	   else
	   {
		   System.out.println("No");
	   }

}

}
can you help
some of my testcases are not passing

can any one help what is wrong with this code
#include<bits/stdc++.h>
using namespace std;

int main(){
int n,m,k,s;
cin>>n>>m>>k>>s;
char arr[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>arr[i][j];
}
}
int flag=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(k>s){
flag=1;
break;
}
if(arr[i][j]==’.’){
s=s-2;
}
else if(arr[i][j]==’*’){
s=s+5;
}
else if(arr[i][j]==’#’){
break;
}
if(j!=m-1){
s–;
}

    }
    if(flag){
        break;
    }
}
if(s>k)
 cout<<"Yes\n";
else
 cout<<"No\n";

}

You did some mistakes with (’ ', s–, cout<<s<<endl) and I improve your code now you can submit it
#include<bits/stdc++.h>
using namespace std;

int main()
{
int n,m,k,s;
cin>>n>>m>>k>>s;
char arr[n][m];
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
cin>>arr[i][j];
}
}
int flag=0;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
if(k>s)
{
flag=1;
break;
}
if(arr[i][j]==’.’)
{
s=s-2;
}
else if(arr[i][j]==’*’)
{
s=s+5;
}
else if(arr[i][j]==’#’)
{
break;
}
if(j!=m-1)
{
s–;
}

    }
    if(flag)
    {
        break;
    }
}
if(s>k)
   {
	cout<<"Yes\n";
	 cout<<s<<"\n";
   }

else{
    cout<<"No\n";
}

}

Hi can anyone tell me why this it unable to pass 2 test cases. I am unable to figureout what is wrong.

#include<iostream>
using namespace std;


void escapePark(char *p, int n, int m, int s, int k)
{
	bool flag = true;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			char ch = *(p+i*n+j);

			if(s < k)
			{
				flag = false;
				break;
			}
			if(ch == '.')
				s = s-2;

			if(ch == '*')
				s = s+5;

			if(ch == '#')
				break;

			if(j != m-1)
				s--;

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


int main() {

	int n, m, k, s;

	cin >> n >> m >> k >> s;

	char p[n][m];

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
			cin >> p[i][j];
	}

	escapePark((char*)p, n, m, s, k);

	


	return 0;
}

Can someone explain what is wrong with my code? I am getting wrong answer for 2 test cases

#include
#include <bits/stdc++.h>
using namespace std;

void check(char arr[][100],int m, int n, int k, int s){
bool ans=true;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(s<k){
ans=false;
break;
}
if(arr[i][j]==’.’){
s-=2;
}
else if (arr[i][j]==’#’) break;
else s+=5;

		if(j!=m-1) s-=1; 
	}
}

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

}

int main() {

int n,m,k,s;
cin>>n>>m>>k>>s;
char arr[100][100];

for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
		cin>>arr[i][j];
	}
}

check(arr,n,m,k,s);

return 0;

}