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

Автор KrK, 13 лет назад, По-английски

Hello.
I submitted this code to this problem with option "GNU C++ 4.6" and received "WA on test 1".
Output was:
1
CS
while the expected answer:
2
SC
However, the program was correct in my pc (I use Dev-C++). I tried to resubmit the same code but with other option "MS C++" and it worked.
So, can somebody explain to me why this code didn't worked with "GNU C++ 4.6"?

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

13 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

It's optimization's problem. I've Compiled your code localy with GCC 4.6 without -Ox flag, and the result is correct, but with -Ox result is wrong
  • 13 лет назад, # ^ |
    Rev. 4   Проголосовать: нравится +4 Проголосовать: не нравится

    UPD: I bored myself for a hour with your source.

    You just have array index out of bounds in the line 32. G++ gives from1[-1] different than MSVC for this specific occasion. Max works incorrectly (because you are comparing with quasi-random value).

    Study to debug your programs yourself. Or use Java as I do... ;-)
    • 13 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      Oh, my silly mistake :) I didn't expect that.
      Thank you for your work. It is clear now.
13 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

By the way I could not reproduce this behavior on my local machine so you can see my submissions with debug outputs to get what I mean more clearer. Especially 599091.