Using recursion would have been the point, but this is such a nice use of the std library that I give you the points.