Hi,
I am having trouble with my submissions. They appear with the expected output in Visual Studio but when I submit them to the Codeforces servers they differ.
For instance the char 2 becomes a question mark (probably unicode problems?)
Can someone please help me?
Thank you.
No, there are no unicode problems.
Here is my guess:
Here,
s[i + 2]
may be out of bounds of the strings
. It is not guaranteed to be zero. if you swap these two characters, thens[i]
may contain some garbage value. And this garbage value will travel to the front of the string.In general, I've noticed that on people's computers, unused memory is likely to be filled with zeroes, and therefore you will not notice these problems or even start thinking that it is guaranteed. But on Codeforces, unused memory seems to be filled with garbage.
Use
-fsanitize=address
to catch it in local run