Skip to content

Instantly share code, notes, and snippets.

@becxer
Last active August 29, 2015 14:14
Show Gist options
  • Save becxer/67b3770e9c1809d3a5bc to your computer and use it in GitHub Desktop.
Save becxer/67b3770e9c1809d3a5bc to your computer and use it in GitHub Desktop.
algorithm solving template for cpp
#include <fstream>
#include <iostream>
#define VERSION "ARGV" //FILE, STDIN, ARGV
using namespace std;
char* INPUT_TEXT = "test.in";
char* OUTPUT_TEXT = "test.out";
int solution(istream& in, ostream& out){
return 0;
}
int main(int argc, char* argv[]){
istream* in = &cin; ostream* out = &cout;
ifstream ifs; ofstream ofs;
if (VERSION == "ARGV"){
if(argc != 2) {
cout << "a.out input.txt" << endl;
return 0;
}
INPUT_TEXT = argv[1];
ifs.open(INPUT_TEXT);
in = &ifs;
}
if (VERSION == "FILE"){
ifs.open(INPUT_TEXT);
ofs.open(OUTPUT_TEXT);
in = &ifs; out = &ofs;
}
return solution(*in,*out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment