0

Now I am doing tideman and I already test and all are working well and get the expected result.but when I check with Check50,I got this msg

:( tideman compiles code failed to compile

I just added one recursive function and If I add this function its says like that, but if I remove this recursive, It works fine and says I have an error.below are locked function and the custom function called isCircle.

bool isCircle(int winner,int loser,int main)
{

    for(int i=0;i<pair_count;i++)
    {
        if(pairs[i].winner == winner && pairs[i].loser == loser){
            continue;
        }

        if(pairs[i].loser==winner)
        {
            **if(pairs[i].winner == main){
              return true;
            }else
            {
               return isCircle(pairs[i].winner,pairs[i].loser,main);

            }**
        }

    }

    return false;
}


void lock_pairs(void)
{
    // TODO
    for(int i=0;i<pair_count;i++)
    {
        if(i<2)
        {          
            locked[pairs[i].winner][pairs[i].loser]=true;
            continue;
        }

        bool circle=isCircle(pairs[i].winner,pairs[i].loser,pairs[i].loser);



        if(circle){
            locked[pairs[i].winner][pairs[i].loser]=false;
            continue;
        }

        locked[pairs[i].winner][pairs[i].loser]=true;

    }
    return;
}

I added this iscircle function and if I remove this following lines from isCircle function it working.

                if(pairs[i].winner == main){
                    return true;
                }else
                {
                   return isCircle(pairs[i].winner,pairs[i].loser,main);

                }

What happening? What is wrong in this isCircle?

1 Answer 1

0

I wouldn't call a variable main. This could lead to confusion.

In this case, the checker renames int main into int distro_main and adds its own main function. This would go wrong if this particular string appears in the file in other context.

So rename your main parameter.

Besides, your recursive function could perfectly work with only two parameters, if you only used locked edges, not all pairs.

3
  • Can u explain a bit more? I am stuck in recursive function.
    – Loran
    Commented Feb 5, 2020 at 6:32
  • Explain what? Your compile error I would expect to be caused by you using int main, so renaming the parameter should fix that. And your recursive function should rely on locked, not pairs, but that's not a compile issue.
    – Blauelf
    Commented Feb 5, 2020 at 6:56
  • After I fixing the name issue, I got this error "lock_pairs skips middle pair if it creates a cycle". How can I test this one to get this error?
    – Loran
    Commented Feb 5, 2020 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .