USACO setup

Posted on Mon 28 March 2016 in Programming

USACO is fun. Though it is fairly easy to get up and running on the platform, there remain a few repetitive steps during problem solving that can be automated. Here is a brief summary of my automation steps:

  1. Use a template. Here is mine. Save it as template.cpp:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
ID: sinha.k1
PROG: TEMPLATE
LANG: C++11
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <utility>
#include <iomanip>
#include <bitset>
#include <fstream>
#include <limits>

using namespace std;

typedef long long int64;

int main(int argc, char const *argv[]) {
    ofstream fout("TEMPLATE.out");
    ifstream fin("TEMPLATE.in");

    fin.close();
    fout.close();
    return 0;
}
  1. Save this script as solve.sh in the same directory as above:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

if [[ $# < 1 ]]
then
    echo "Usage: ./solve.sh <PROBLEM_NAME>"
    exit -1
fi

PROBLEM_NAME="$1"
TEMPLATE_FILE="template.cpp"

# Clone template
echo "Cloning template $TEMPLATE_FILE ..."
cp "$TEMPLATE_FILE" "$1.cpp"
sed -i -- "s/TEMPLATE/$1/g" "$1.cpp"
echo "Template successfully cloned into $1.cpp"

# Create input file
echo "Creating input file $1.in ..."
touch "$1.in"
echo "Input file $1.in successfully created"

# Success!
echo -e "\nDone! All the best!"
  1. All done! Whenever you’re ready to begin coding a solution, simply execute ./solve.sh PROBLEM_NAME

All the best!