some algorithm by java C++