Slight optimization in C++ Problem 39