hey i have compile the same code on gdb compiler in c language and the answer is 11 but when i compile on your IDE in c++ lang. answer is 13, please tell the reason and one another doubt you said that when j!=n-1 then always s-- but if we are on our zeroth index ( that is zeroth row and zeroth column) which is “.” then we also do not need to do 1 minus as we are on starting point…but according to ur code compiler always do 1 minus except at last col.
please clarify this asap. THANK YOU
Piyush magical park doubt
hey ,@lovish2552
you have to do s-- whenever you take any step except from the last col to first col of other row, your first step will be from (0,0) to (0,1) so if it is possible to reach (0,1) then only do s–,
else for other queries send me your code i will check it.
#include <stdio.h>
void magicalpark(char a[][100],int m,int n,int k,int s)
{
bool success= true;
int i,j;
char ch;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
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)
{
printf("YES\n");
printf("%d",s);
}
else
printf("NO");
}
int main()
{
char a[100][100];
int i,j,n,m,s,k;
scanf("%d %d %d %d",&m,&n,&k,&s);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%c ",&a[i][j]);
}
}
magicalpark(a,m,n,k,s);
return 0;
}
This is my code and output of the same test case is 11 in gdb compiler
your code is giving wrong answer cause your code is never taking input correctly.
while taking array input take input as scanf(" %c",&a[i][j]), since there may be whitespace or endline in input buffer so first give space then write %c
Thanks a lot …now my code is running