Magical Park - Fails Test Cases


Code is working fine in my ide but here in the challenge ide it fails all the test cases. Please guide me in correcting it.

@mvermav19

  1. In both the nested for loop you are iterating from j = 0 to r instead of c
  2. You also need to check whether s>=k or not in every iteration of the for loop if not then print “No”

sir, it still fails two test cases

@mvermav19

You didn’t change this nested for loop for input

for (int i = 0; i < r; i++){
        for (int j = 0; j < r; j++){ //change it to c
            cin >> a[i][j];
        }
}

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.

sir i have changed that and also updated the code but still it fails two test cases

@mvermav19
Try this,

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

int main()
{
    int r, c, k, s;
    cin >> r >> c >> k >> s;
    cin.get();

    char a[r][c];
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            if (k > s)
            {
                cout << "No\n";
                return 0;
            }

            if (a[i][j] == '.' and j != c - 1)
            {
                s -= 3;
            }
            if (a[i][j] == '*' and j != c - 1)
            {
                s += 4;
            }
            if (a[i][j] == '.' and j == c - 1)
            {
                s -= 2;
            }
            if (a[i][j] == '*' and j == c - 1)
            {
                s += 5;
            }
            if (a[i][j] == '#')
            {
                break;
            }
            
        }
    }
    if (s >= k)
    {
        cout << "Yes" << endl
             << s;
    }
    return 0;
}

Now it’s working fine, sir.

1 Like