Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HackerRank Encryption Problem https://www.hackerrank.com/challenges/encryption
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
string calc(string msg){
int len,row,col,allot,margin;
string str="";
len=msg.length();
row=floor(sqrt(len));
col=ceil(sqrt(len));
if(row*col<len)
row++;
margin=row*col-len;
allot=row*col;
for(int i=0;i<col;i++){
for(int j=0;(i+j)<len;j+=col)
str+=msg[i+j];
str+=" ";
}
return str;
}
int main() {
string msg;
cin>>msg;
cout<<calc(msg);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment