from usaco: usacoprobfix.htm
- Put sanity checks around all array indexing (Pascal does this by default). The assert() (from assert.h) routine is a nice tool for this. assert() fails if the parameter is 0 (false). If this happens, assert will stop the program and print out an error message saying which assert on which line failed. The really nice thing about assert is that you can #define NDEBUG for including assert.h and the assert operations go away, so that you can put a lot of debugging in and not run it when you want the code to be fast. Consider:
int i, j, quotient; i = 8; j = 0; assert (j != 0); quotient = i/j;
orint i, j, chessboard[8][8]; assert (0 <= i); assert (0 <= j); assert (i < 8); assert (j < 8);
Why four statements? Because the compound statement doesn't give you enough data when failure occurs.
google c++ style