Roufie's blog

By Roufie, history, 6 weeks ago, In English

Hi,

I'm new to Codeforces and have been looking code into submissions by others. I'm new to C++ as well and can't find any articles on what these snippets of code do. Can someone please explain?

I understand that the code in If block gets executed when LOCAL is set. But what does the code actually do? What is alog/debug.g? What is debug(...) 42 meant for?

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

Source: https://codeforces.com/contest/1712/submission/168158904

#ifdef LOCAL
	#define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
#else
	#define eprintf(...) 42
#endif

Source: https://codeforces.com/contest/1716/submission/166973182

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

»
6 weeks ago, # |
Rev. 2   Vote: I like it +42 Vote: I do not like it

.h is called a header file, and is basically a library of code that either you make (or downloaded), or it comes with the compiler. Content-wise, it looks just like a C++ source file without a main()

A demonstration will be useful. Do the following:

  • Make a C++ file like how you usually do on your computer. Paste this code in.
something.cpp
  • Make a folder named algo, in the same folder with your C++ file.
  • Make a file named sum.h inside algo, then paste this code.
sum.h
  • Now run the C++ code (the "something.cpp" file)

You can do include in the header file, or add more stuff inside that header file, or add even more header files to the algo folder, or do any customizations you want to make your own algo library.

debug.h is probably just their own custom-made header file for debugging CP codes if needed. You might be able to find some online, or you can make one by yourself.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Stop trying to figure out how um_nik's mind works, you are doing it wrong, go and solve some problems.

Some jokes. IMO, as u accumulating more knowledge and implementing more and more code, at any unknown moments, u could unexpectedly understand some things that could seemed weird before. U would only find something brainy(helpful) when its meeting your current demands/situation.

More specifically, u may understand the use of the mentioned code when u are writing some “large” problems or u simply want to code faster.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Curiosity doesn't always kill the cat :p