It gives me a segmentation fault, because you first say “1 test case, 100 piles” but then you enter 1000 stones FOR 1000 piles (the for condition is wrong, it should be ‘i<100’ instead of ‘i<1000’), right?
After I’ve corrected that, the answer is the same as the other solution. 1 says bob, and the “wrong” solution says bob too. I’m still stuck at understanding why my other solution is wrong I made the buffer 500 elements big, because in the “biggest” scenario… I would need 5 char 100 times, like '1000 '. But, when the last ‘1000’ comes, it would have a ‘\0’ instead of a ’ ’ after it.
So the problem was in the additional escape sequence ‘\r’ ?
The getchar()s only ate the ‘\r’, leaving the ‘\n’ in the input buffer.
So the gets() would only get a ‘\n’ and continue to the next test case.
Was this the problem?
I fixed it with a double getchar() after every Enter (I suppose I could also use a loop like while((ch = getchar()) != EOF && ch != ‘\n’); right before the gets() call).