problem
The follwing code, a part of solution for BOJ 2753 does not print as expected.
cout << (!(year % 4) && (year % 100)) || !(year % 400);
solution
Refer to c++ operator precedence. Operater ‘«’ has greater precedence than ‘||’. Therefore, the code above will behave as following:
(cout << (!(year % 4) && (year % 100))) || !(year % 400);
Update the code as following to ensure inteded behavior.
cout << ((!(year % 4) && (year % 100)) || !(year % 400));