Skip to content

Instantly share code, notes, and snippets.

View dilijev's full-sized avatar

Doug Ilijev dilijev

View GitHub Profile
@dilijev
dilijev / test.cpp
Created September 2, 2012 22:07
My solution to Sphere's TEST problem.
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main() {
string str;
while(cin>>str) {
if(!str.compare("42")) break;
@dilijev
dilijev / .bashrc
Created September 10, 2012 03:51
Snippet from my .bashrc that shows my current colorful prompt.
source ~/.bash_colors
#...
PS1="${RED}\t ${GREEN}${debian_chroot:+($debian_chroot)}\u@\h${NORMAL}:${BRIGHT_BLUE}\w${NORMAL}\$ "
@dilijev
dilijev / const1.cpp
Created October 7, 2012 02:56
Snippet from a file, playing with constants.
int i1 = 111;
int i2 = 222;
int i3 = 333;
int i4 = 444;
// Neither the data nor the pointer are const
int* a = &i1;
// Constant data, non-constant pointer
const int* b = &i2;
@dilijev
dilijev / interview1.cpp
Created October 7, 2012 03:02
const ptr and const data
const int* const * ptr;
@dilijev
dilijev / const2.cpp
Created October 7, 2012 06:25
these lines have the same type
const int a = 11;
int const b = 22;
@dilijev
dilijev / const3.cpp
Created October 7, 2012 06:30
legal and illegal const expressions with pointers
int n = 42;
const int* const a = &n;
int const* const b = a; // same type as a
// const int const * c = b; // "error: duplicate const"
@dilijev
dilijev / interview2.cpp
Created October 7, 2012 06:34
rephrasing the interview question
int n = 42;
int* p = &n;
const int* const * a = &p; // given (interview question)
int const* const * b = a; // rephrased version
@dilijev
dilijev / wrong_answer.cpp
Created October 7, 2012 06:44
the correct way to write the wrong interview answer
const int** const ptr;
@dilijev
dilijev / DimensionException.cpp
Created October 21, 2012 06:25
DimensionException
class DimensionException : public std::exception {
private:
size_type _rowsA;
size_type _colsA;
size_type _rowsB;
size_type _colsB;
char _what[256];
public:
DimensionException()
: exception() {
/**
Compile with
g++ matrix.cpp -o matrix
Run with
./matrix
*/