nov cookoff 2014 brackets solution problem

bracket

#1

what is wrong with my solution? it matches which solution which are ac. http://www.codechef.com/viewsolution/5449895


#2

The problem I believe is with these lines:

 if(s*=='(')
{balance= balance++;}
if(s*==')')
{balance= balance--;}

When you are incrementing or decrementing a variable, you should just use:

balance++;
balance--;

#3

You cannot rely on a statement:

x = x++;

or

x = x--;

because it is undefined in C++, check it here:


#4

Your solution is not working for example from problem statement…


#5

you told me what the problem was but why it is a problem in my solution. can you please help.


#6

simply because incrementing or decrementing doesnt work like balance = balance++;


balance++ is the equivalent of balance = balance + 1, another type is balance += 1;


#7

I found this - http://stackoverflow.com/questions/16323179/how-does-a-a-work-in-java

in C it’s undefined behavior


#8

okay this is very interesting discussion topic…