My terrible experience with freopen()

Revision en2, by szawinis, 2016-12-24 20:19:38

So, just a few hours ago, we finished a contest on a Thai site, namely Codecube. The round consisted of 6 problems to solve in 3 hours. I was feeling confident at first ACing two problems in 15 minutes. Then came the third problem, which was a typical two pointers + data structures. I was almost certain I could solve the problem, and started to code the solution. Many minutes passed by, and I finally got the solution. I submitted it, and got a WA slapped on my face. So, I simply moved on to the fourth problem and ACed it, because finding bugs is time consuming. I later returned to the third problem, and tried finding the bug for almost an hour with no luck, only to find out that the only line I messed up on was: freopen("data.txt", "r", stdin);, which I forgot to uncomment. I later submitted after the contest and got AC just with that line commented out. Absolutely disappointing.

As many of us know, the freopen command is used to redirect stdio to file IO. This is particularly useful when testing your program on a local machine because you can avoid copying and pasting the test data every time you want to debug. However, one of the problems I have experienced when using it is I forget to uncomment it out when submitting. This is a huge problem, especially on CF where many points are deducted for resubmission. I don't know if it's bad luck, but this has happened to me several times already. For anyone who is experiencing the same problem, I think the solution here is simply to write comments to remind yourself. Has this ever happened to any of you guys? Or is it just me being awfully stupid?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English szawinis 2016-12-24 20:19:38 370 (published)
en1 English szawinis 2016-12-24 20:14:14 1314 Initial revision (saved to drafts)