Rewrote two problems in C++