Improved the solution to the Brackets problem in C++