Skip to content

Instantly share code, notes, and snippets.

@nhocki
Created September 23, 2014 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhocki/2334f56dc5b4446152d7 to your computer and use it in GitHub Desktop.
Save nhocki/2334f56dc5b4446152d7 to your computer and use it in GitHub Desktop.
Topcoder cpp template
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define D(x) cout << #x " is " << x << endl
vector<string> split( const string& s, const string& delim =" " ) {
vector<string> res;
string t;
for ( int i = 0 ; i != s.size() ; i++ ) {
if ( delim.find( s[i] ) != string::npos ) {
if ( !t.empty() ) {
res.push_back( t );
t = "";
}
} else {
t += s[i];
}
}
if ( !t.empty() ) {
res.push_back(t);
}
return res;
}
vector<int> splitInt( const string& s, const string& delim =" " ) {
vector<string> tok = split( s, delim );
vector<int> res;
for ( int i = 0 ; i != tok.size(); i++ )
res.push_back( atoi( tok[i].c_str() ) );
return res;
}
class $CLASSNAME$ {
public:
$RC$ $METHODNAME$($METHODPARMS$) {
$RC$ res;
return res;
}
$WRITERCODE$
};
$BEGINCUT$
#define ARRSIZE(x) (sizeof(x)/sizeof(x[0]))
template<typename T> void print( T a ) {
cerr << a;
}
static void print( long long a ) {
cerr << a << "L";
}
static void print( string a ) {
cerr << '"' << a << '"';
}
template<typename T> void print( vector<T> a ) {
cerr << "{";
for ( int i = 0 ; i != a.size() ; i++ ) {
if ( i != 0 ) cerr << ", ";
print( a[i] );
}
cerr << "}" << endl;
}
template<typename T> void eq( int n, T have, T need ) {
if ( have == need ) {
cerr << "Case " << n << " passed." << endl;
} else {
cerr << "Case " << n << " failed: expected ";
print( need );
cerr << " received ";
print( have );
cerr << "." << endl;
}
}
template<typename T> void eq( int n, vector<T> have, vector<T> need ) {
if( have.size() != need.size() ) {
cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements.";
print( have );
print( need );
return;
}
for( int i= 0; i < have.size(); i++ ) {
if( have[i] != need[i] ) {
cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << ".";
print( have );
print( need );
return;
}
}
cerr << "Case " << n << " passed." << endl;
}
static void eq( int n, string have, string need ) {
if ( have == need ) {
cerr << "Case " << n << " passed." << endl;
} else {
cerr << "Case " << n << " failed: expected ";
print( need );
cerr << " received ";
print( have );
cerr << "." << endl;
}
}
$ENDCUT$
$BEGINCUT$
int main( int argc, char* argv[] ) {
$MAINBODY$
return 0;
}
$ENDCUT$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment