Ad
  • Default User Avatar
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Unfortunately, in C and C++ things are not that easy.

    Invalid memory access is defined in C++ as a cause of undefined behaior, and this can mean anything. In your case, your solution writes outside of the result buffer and modifies something which is later on used to calculate reference solution, or to print the message, or anything else. When undefined behavior happens, there are no guarantees anymore: anything can change, anything can break, even things apparently unrelated.

    If I were to guess, sprintf puts null terminator right behind your buffer, and probably g variable happens to be located there on the stack, messing up further computations. But it's just guessing, and it can be wrong or can change from run to run.

  • Custom User Avatar

    I'm not claiming my code is perfect by any means - I'm here to learn after all.

    But my terrible code shouldn't change the expected values? The first print in my first screenshot was the first line in the function

    the expected values are still 0, which is what my original issue was for

  • Custom User Avatar

    From all the things which are wrong with your solution, the wrongest ones are probably buffer overflow and missing includes.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
  • Custom User Avatar

    Oh, Perhaps i'm missing something then.

    The basic tests work fine, but none of the random ones do. I put some logs in to the code - as you can see here https://imgur.com/a/quZ5I95

    Every random test results the same thing, my debugs display a (seemingly correct?) logical progression to a non-0 Hex value, but then the expected value always has the green value as 00.

  • Custom User Avatar

    C++ tests seem to be fine.

  • Custom User Avatar

    C++ Does not work, Basic tests are fine, but all random tests expect values as if green was 0.