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

Автор PathToMaster, история, 7 недель назад, По-английски

Hello, Codeforces. I know you all have been there: coding a solution that gives a wrong answer and then being many minutes, or even hours, trying to find the bug in the code, becoming frustrated because you feel you are wasting time you could be using solving other problems. Have you any tips or a strategy for successfully debugging incorrect solutions?

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

»
7 недель назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

write a brute force solution which gives correct answer and test your current solution by generation random numbers using generator and find the test case where your solution result in wrong answer

»
7 недель назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

As a software engineer, I apply engineer-like strategies.

1 . Write readable code to make logic clear and minimize bugs

  • use lambda functions for logic repeated more than twice.
  • assign calculation results to variables to clarify their meaning
  • give variables short but descriptive names

2 . Print debugging -> cpp-dump

»
7 недель назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

Understand what each section is doing. Then Just check line by line. Think about whether it's reasonable carefully. Pay special attention to the interaction between operations.

In addition, you can write down error-prone things before you write code.

You can read um_nik's blog. I think it's meticulous and useful.