You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star :) )
std::string encryption(std::string & _plainText) { using namespace std; _plainText.erase( remove(begin(_plainText),end(_plainText), ' '), end(_plainText)); auto sqrtLength = sqrt(_plainText.size()); auto cols = static_cast<size_t>(ceil(sqrtLength)); auto cipherText = string(); cipherText.reserve(_plainText.size() + cols); for(auto col = 0; col < cols; ++col){ for(auto idx = col; idx < _plainText.size(); idx += cols ){ cipherText += _plainText.at(idx); } cipherText += ' '; } return cipherText.erase(cipherText.size() - 1); }
Seems like cookies are disabled on this browser, please enable them to open this website
Encryption
You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star :) )