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

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

Hello!

Can anyone explain why my submission: 77862595 to the problem: 1340B - Nastya and Scoreboard is giving a RUNTIME_ERROR with exit code 2147483647 ? It works correctly on my macOS's Zsh terminal.

I tried to get a better understanding using a few online compilers:

  1. cpp.sh Exit code: 0 (normal program termination)

  2. onlinegdb.com *** Error in `./a.out': double free or corruption (out): 0x00000000024daec0 *** ( Note: the address is different every time)

  3. repl.it double free or corruption (out) exited, aborted

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

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

What a pity! I don’t know why neither. I think you should check your code again.

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

In main, one of your loops has a condition of while(k>0 && i>=0), but then inside the loop you have i--;. This causes i to be -1 and then when it is used as an index, that causes undefined behavior.