Problem 018, C++