c++ solution