KrK's blog

By KrK, 13 years ago, In English

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"?

  • Vote: I like it
  • +11
  • Vote: I do not like it

13 years ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

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 years ago, # ^ |
    Rev. 4   Vote: I like it +4 Vote: I do not like it

    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 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      Oh, my silly mistake :) I didn't expect that.
      Thank you for your work. It is clear now.
13 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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.