MAESTROolson's blog

By MAESTROolson, history, 2 years ago, In English

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.

  • Vote: I like it
  • -15
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

No, there are no unicode problems.

Here is my guess:

if ((s[i] > s[i+2])&&(s[i+2] > 0))
{
  temp = s[i];
  s[i] = s[i + 2];
  s[i + 2] = temp;
}

Here, s[i + 2] may be out of bounds of the string s. It is not guaranteed to be zero. if you swap these two characters, then s[i] may contain some garbage value. And this garbage value will travel to the front of the string.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it +7 Vote: I do not like it

    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.