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

Автор tirtha_raj, история, 21 месяц назад, По-английски

In today's contest(Problem C), I did a pretty silly mistake where I redeclared a variable inside a loop due to which the global variable was not getting updated. Hence I was trying to find the fault in my logic and Spent exactly 1 hour and 40 minutes regretting my life. While going through my solution now I discovered this and now I want to kill myself.

Now in all seriousness how do I stop repeating these silly errors in the heat of the contest? I have been doing these a lot lately.

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

»
21 месяц назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

I'd say just keep coding and facing these issues until they're gone. There used to be a time when I also was making way too many stupid mistakes like that and it's mostly over now. The thing is even if it happens few times then next time there is a better chance that you'll pay attention to such stuff when coding.

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

The same happens with me, but at least now we know what not to do. ¯_(ツ)_/¯

»
21 месяц назад, # |
  Проголосовать: нравится +72 Проголосовать: не нравится

-Wshadow

»
21 месяц назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

Don't waste a lot of time, deleting and rewriting the solution can be a good option if you are confident that your approach is correct.

Debugging tools can also be helpful in identifying errors in the code, also using good names for your variable.

I have noticed that many people rely on print statements for debugging. But I believe that debugging tools are highly useful, but they seem to be underrated and rarely recommended, particularly in competitive programming.

  • »
    »
    21 месяц назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I have "Debug Mode" in my environment which is pretty good to detect any compilation and runtime problems.

    P.S g++ -O3 -std=c++20 -Wall -Wextra -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fsanitize=bounds -fno-sanitize-recover -fstack-protector

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

One very simple solution: name your variable in a distinct way. Also if you know how to debug, this mistake should be very noticeable.