Last active
December 21, 2015 13:59
-
-
Save djadmin/6316249 to your computer and use it in GitHub Desktop.
HackerRank Encryption Problem
https://www.hackerrank.com/challenges/encryption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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