Ad
  • Custom User Avatar

    Thanks a lot. I now understand what the issue was and the code works here as well.

  • Custom User Avatar

    Is there a way to debug the code here by stepping through all instructions? That's how I debugged it in Visual Studio

  • Custom User Avatar
    std::cout << int("hello"[5]);
    

    prints out 0
    or just nothing when not casting it to an int

  • Custom User Avatar

    my problem is that it is only incorrect in the codewars compiler. The output I get from spinWords("Welcome") in my "test" in the main() function in my code is right:

     std::cout << spinWords("Welcome");
    

    Output in godbolt:

    Program returned: 0
    Program stdout
    emocleW
    

    the word "Welcome" has more than 4 letters hence it's reversed.

    Now another test:

    std::cout << spinWords("codewars compiler hates me xXxX xxxxxX");
    

    and the output:

    Program returned: 0
    Program stdout
    srawedoc relipmoc setah me xXxX Xxxxxx
    

    as you can see my algorithm is not the problem. It works everywhere but codewars.

  • Custom User Avatar

    Hi again, sorry for the late reply to my own question, but the main function was only for the code to compile on godbolt and I removed it whenever testing it on codewars. In main() I just cout'ed the output from my spinWords to show that the algorithm works. The test has the same input as in cout in the main() function. In main(), my function outputs the same as the expected output from the test but fails the test when compiled on codewars.

  • Custom User Avatar

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

  • Custom User Avatar

    I coded (C++) the algorithm in visual studio, everything works. I copied the code in here and suddenly it's broken. Compiles and works on godbolt and same compiler. Any ideas?