2
\$\begingroup\$

What are the rules for using c++ in code golf? In TIO, there is a header section and a footer section. Can you put your #includes in the header section?

Do you use this template?

HEADER: [#include...]
CODE: <function>
FOOTER: <main method, runs function>

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ If in doubt, submit a full program. \$\endgroup\$
    – DELETE_ME
    Mar 25, 2018 at 9:27

1 Answer 1

7
\$\begingroup\$

If your submission require the includes, then no you may not put the #includes in the header. It is consensus that imports/includes should count towards your score.

The reason the header and footer exist is so that you can put boilerplate code in there for testing your program, but then have your byte count not be affected by the boilerplate. For example, if you submitted a function to add two numbers together, such as

int s(int a,int b){return a+b;}

then this is a valid 31-byte solution. However, people looking at it can't immediately verify that this solution is correct because it needs certain boilerplate to run. So you could put some additional code in the header and footer to make it a testcase, like Try it online! without drastically inflating your byte count.

Note that here, I am putting the #include <iostream> in the header because that is needed for the testcase, not the function. If you were submitting a function that required a library such as string or vector, then that would still need to go under code and count towards your byte-count.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .