Solving random problems in C/C++