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

Автор Roufie, история, 2 года назад, По-английски

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://mirror.codeforces.com/contest/1712/submission/168158904

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

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

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

»
2 года назад, # |
Rev. 2   Проголосовать: нравится +42 Проголосовать: не нравится

.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.

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

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.