6

Same code outputs right and wrong answer with different compilers

 1 year ago
source link: http://codeforces.com/blog/entry/107972
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Hello! I have a funny problem. I was solving a problem in C language and submitted a code. It showed wrong answer in test 1 when compiled with gcc compiler. But when I compiled the same code with g++ compiler, it gave the right answer. The code was written in C. Can anyone please explain this??? I am giving the submission links. Thanks in advance.

https://codeforces.com/contest/1742/submission/176129339

https://codeforces.com/contest/1742/submission/176129401

102 minutes ago, # |

Rev. 2  

0

Sorry, but didn't you try to think about it?

Input:
1) Code gives different verdicts in different compilers;
2) In first testcase you got in C-solution 5 instead of 6;

Question you should be got in head: is everything all right in your code? (there so many blogs already with same "different compilers give different results, is it bug?"; No it is never bug in compilers, it's always bug in code).

You know input in which you've got trouble. Try to "debug" it with paper and pen (or with gcc sanitizers if you know how to use it), and you will find trouble in code (I think that if you find it yourself it would be more enjoyable, maybe I'm wrong:)

If after debug you've got nothing, then I'd assume that you don't know some shit about C/C++. But still, try it yourself first:)

  • 65 minutes ago, # ^ |

    Rev. 2  

    0

    Thanks a lot. I am a beginner. So I didn't understand it the first time around. Will try to debug it. Thanks again.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK