# Hackerrank challenges for a programming course: hide code and show only what is relevant?

I'm trying to create a programming competition with personalized challenges for my class, using Hackerrank.

The thing is: I need to show only the minimum relevant code to solve the challenge, and leave out any extra code needed to run the test cases, since this will just be confusing for beginners trying to learn programming.

I created an easy challenge where participants should write a C++ function to determine if a given year is a leap year or not. I created the challenge and some test cases. But when I preview the challenge I get a template like this showing up:

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}


First problem is: it's importing too many additional headers and stuff that won't be used here. And also, it would be better to show just the function signature, so I created a stub using the language they provide for it:

function(boolean, leapyear, integer x #ADD YOUR CODE HERE)
integer(x)
invoke(boolean, result, leapyear, x)
print(boolean, result)


When I save it I can see in the Body section the function signature I want:

But now when I preview it, it's showing me all that "head" and "tail" information, which I don't know how to hide:

#include <bits/stdc++.h>

using namespace std;

string ltrim(const string &);
string rtrim(const string &);

/*
* Complete the 'leapyear' function below.
*
* The function is expected to return a BOOLEAN.
* The function accepts INTEGER x as parameter.
*/

bool leapyear(int x) {

}

int main()
{
ofstream fout(getenv("OUTPUT_PATH"));

string x_temp;
getline(cin, x_temp);

int x = stoi(ltrim(rtrim(x_temp)));

bool result = leapyear(x);

fout << result << "\n";

fout.close();

return 0;
}

string ltrim(const string &str) {
string s(str);

s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
);

return s;
}

string rtrim(const string &str) {
string s(str);

s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
s.end()
);

return s;
}


So, writing code stubs seem to be the way to go, provided I can hide that "head" and "tail" information.

Does anyone know how to do this? or at least how to hide all the #include madness if I use the default template?

• Why don't you just make an includes.h-file with all the include madness and just include this file? In my opinion that would be the easiest solution! – csabinho Sep 14 '19 at 21:39