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.


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.


Provide a submission link instead of pasting your solution (https://www.codechef.com/viewsolution/24974015 in your case).
I didn’t look at your whole code but in line 10 it should be scanf("%s",arr); instead of scanf("%s",&arr);. &arr will be a pointer to arr. what you need is arr itself which is a pointer to your array.

Unfortunately the fix doesnt work. I cant figure out the problem with the logic as the code gives correct answer for all the manually typed testcases.

Declare arr to be of size 101 or more instead of 100 to include the ending Null character.
I am looking for small mistakes instead of the whole thing because that’s what is wrong in most cases and I know this problem can be done using a much smaller loop.

You can try explaining briefly what your solution was so that other people can help you. DON’T post that as a reply, edit the original post. Also replace all that code with the submission link.

@psaini72 Changing the size of the array didnt work. And i’ve explained the logic in the edit as well.
Have a look.