nov cookoff 2014 brackets solution problem

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

The problem I believe is with these lines:

 if(s[i]=='(')
{balance= balance++;}
if(s[i]==')')
{balance= balance--;}

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

balance++;
balance--;
2 Likes

Your solution is not working for example from problem statement…

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

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

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

4 Likes

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

in C it’s undefined behavior

You cannot rely on a statement:

x = x++;

or

x = x--;

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

1 Like

okay this is very interesting discussion topic…