When I was doing oj today, I defined two macros:
# Define max_2 (a, B) a> B? A: B max_3 (a, B, c) (a> B? A: B)> c? (A> B? A: B): c
Then the program results are always WA, and the logic of the program is carefully checked over and over again, so I am crazy. Finally, I found that there are problems with the two macros I have defined. Changed to the following:
Max_2 (a, B) (a> B? A: B) max_3 (a, B, c) (a> B? A: B)> c? (A> B? A: B): c)
The analysis process is as follows:
First, the above two problematic codes:
# Include <iostream> max_2 (x, y) x> y? X: y a = max_2 (,) + B = max_2 (,) + c = max_2 (, d = max_2 (, e = (max_2 (,) + <a <B <c <d <e <
Running result:
From the program variables c and d, we can find that max_2 (x, y) returns the correct results regardless of the order of x and y;
From the program variables a and B, we can find that the operation sequence is related to the order of x and y in max_2 (x, y). When x> y, the program first converts max_2 (2, 1) instead of adding 3 to B;
From the program variable e, we can find that even with parentheses, this operation sequence cannot be changed.
Another piece of problematic Code, for example, compilation fails:
Therefore, do not forget the key brackets. Otherwise, they will be harmless.