Skip to content

Instantly share code, notes, and snippets.

@djadmin
Last active December 21, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djadmin/6316249 to your computer and use it in GitHub Desktop.
Save djadmin/6316249 to your computer and use it in GitHub Desktop.
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