Piyush and Magical Park testcase fail

#include<stdio.h>
#include<string.h>
int main()
{
int m,n,i,j,s,k,g;
scanf("%d%d%d%d",&m,&n,&k,&s);
char a[n][m];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%c",&a[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]==’.’&&j!=0)
s=s-3;
else if(a[i][j]==’’&&j!=0)
s=s+4;
else if(a[i][j]==’#’&&j!=0)
{
s=s-1;
break;
}
else if(a[i][j]==’.’&&j==0)
s=s-2;
else if(a[i][j]==’
’&&j==0)
s=s+5;
else if(a[i][j]==’#’&&j==0)
{
break;
}
if(s<k)
{
g=1;
}

    }
}
if(s<k||g==1)
{
        printf("NO");
}
else
  {
      printf("YES\n");
    printf("%d",s);
  }

}

Hello @Shivam31,

There are few mistakes in your code:

  1. When # is encountered, you are required to break further iteration.
    But, in your code, you are not breaking out of the outer loop.
    Solution:
    https://ide.codingblocks.com/s/108475

  2. The way you are taking inputs, the space is also considered as input.
    To better understand this, print the matrix after taking input.
    Solution:
    scanf(" %c",&a[i][j]);
    Add a space before %c. This way compiler will ignore all the white spaces.

Hope, this would help.
Give a like, if you are satisfied.

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.