Блог пользователя MAESTROolson

Автор MAESTROolson, история, 2 года назад, По-английски

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.

  • Проголосовать: нравится
  • -15
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # ^ |
      Проголосовать: нравится +7 Проголосовать: не нравится

    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.