Can someone help me with my code…? I have written the correct code for this question using the last character determination approach. But i developed the following logic as well and cant figure out the problem.

https://www.codechef.com/viewsolution/24974998

Here is my approach:

I have used the first ‘if’ statement and the last two ‘else if’ statements to find the winner if there is no tie(i.e flag=0) .

Now if there is a tie : flag=1 which is done using the second if statement.

Now when flag =1, the first ‘else if’ statement comes into picture.

Here i have used the chance variable to check that whether the two points have been scored (chance=1 for win 0 for the lose) simultaneously.

I know the approach is very complicated and this could also be done in an easy way but im just curious to know the problem with the logic here.

Thanks.