algorithm by c++