Piyush and magical park

although my code fulfills every condition given in question , on submitting it is showing wrong answer. kindly tell me where i m wrong.

Anubhav, pls share your code by saving on ide so that I could check it.

1 Like

#include<bits/stdc++.h>
using namespace std;
int main() {
int n,m,k,s;
cin>>n>>m>>k>>s;
char a[n][m];
for(int i=0 ;i <n ; i++)
{
for(int j = 0; j< m; j ++)
{
cin>> a[i][j];
}
}
int i = 0,j = 0;
while(j<m && i < n)
{
if(a[i][j]==’’)
{
s+=5;
j++;
s=s-1;
if(j==m-1)
{
if(a[i][j]==’
’)
{
s=s-3;
j=0;
i++;
}
else if(a[i][j]==’*’)
{
s=s+4;
j=0;
i++;
}
else
{
s=s-1;
j=0;
i++;
}
}

}
else if(a[i][j]==’.’)
{
s=s-2;
j++;
s=s-1;
if(j==m-1)
{
if(a[i][j]==’’)
{
s=s-3;
j=0;
i++;
}
else if(a[i][j]==’
’)
{
s=s+4;
j=0;
i++;
}
else
{
s=s-1;
j=0;
i++;
}
}

}
else
{
s=s-1;
j=0;
i++;
}

}
if(s>k)
{
cout<<“Yes”<<endl;
}
else
{
cout<<“No”<<endl;
}
cout<<s;

return 0;

}

Anubhav, I think you have unnecessary made the code complex, basic approach you need to follow up is that you will input the 2-d char array , and then traverse the complete array and then simply check the following conditions in your code as :

  1. if(ar[i][j]==’.’)
    {
    S=S-2;
    S–;
    }

  2. if(ar[i][j]==’*’)
    {
    S=S+5;
    S–;
    }

  3. if(ar[i][j]==’#’)
    {
    N=N+1; // for next row, since the current row gets blocked
    }

  4.  if(ar[i][j]=='#' && i==N-1)  // since you cannot further change to new row as its last row 
     {
       break;
     }
    

Try to implement only these condition, and keep your code simple…

Since, you arent replying anything, I am marking this doubt as resolved… You can reopen it, if u still face any issues…