Problem with code - Piyush and magical park

Can you please help with my code.
Giving WA in first case.

Here’s the problem link -> https://ide.codingblocks.com/s/88401

Try to use this condition inside your loop, if(S<K)
{
break;
}
Since it is mentioned that at any point , if your strength is less than k, break from loop

I have already tried that…Heres my code -> https://ide.codingblocks.com/s/89475


I have modified your code, try to submit it now

Can you please explain me the if else part of the code?

Firstly, in the question it is mentioned that if your strength at any point becomes less than k, you will immediately come out of loop, thts why i have used a break
Then if char is ‘.’, then your strength will decrease by 2, as mentioned in problem, however, you are supposed to reduce your strength at every point when you will move from one character to other, so i use s-- again after that in every condition,
similarly i have used else if condition for ‘*’
Now it is mentioned in problem that whenever ‘#’ encounters, you are supposed to move to next row, thats why i use n=n+1, since that row is blocked for further traversal,
and in final condition, i checked that if you encounter ‘#’ and also you are in last row, then also you cannot move in next row, since it will be out of bound and hence you will break from loop.

I hope you understood the logic.