WA in MYSARA (what is c++'s bodmas?)

WA:CodeChef: Practical coding for everyone

AC:CodeChef: Practical coding for everyone

Only difference is the bracket in the if condition to check whether it’s 0.

everule1-MYSARA-wa.cpp:82:26: warning: suggest parentheses around comparison in operand of ‘&’ [-Wparentheses]
        if(seq[i-1]&seq[i]!=seq[i-1]){
                    ~~~~~~^~~~~~~~~~

The bitwise-and (&) operator has lower priority than the != operator:

https://en.cppreference.com/w/c/language/operator_precedence

3 Likes

@ssjgz In which IDE?

How do I know which condition is done first? Is there some list? Or Is it showing warning because it’s undefined behaviour?

It’s perfectly well-defined behaviour, but a common mistake that humans make :slight_smile:

See the link about operator precedence in my post.

&'s lower priority means that the expression is parsed like this:

if((seq[i-1])&(seq[i]!=seq[i-1])){

No IDE - just using g++ with -Wall -Wextra from the command-line.

3 Likes

@everule1
https://en.cppreference.com/w/cpp/language/operator_precedence

Have a look at operator precedence :slight_smile: