p6-2.cpp solved