Guest User

Encryption:HackerRank

a guest
Feb 27th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. //Author: Nishant Sharma
  2. //HackerRank : Encryption
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <vector>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <map>
  9. #include <math.h>
  10. using namespace std;
  11. int main() {
  12. string strcall;
  13. cin >> strcall;
  14. double j = sqrt(strcall.length());
  15. int len = j;
  16. int col;
  17. j = len * len;
  18. if (j == strcall.length()) {
  19. col = len;
  20. } else {
  21. col = len + 1;
  22. while (col * len < strcall.length()) {
  23. len++;
  24. }
  25. }
  26. int index;
  27. for (int i = 0; i < col; i++) {
  28. for (int k = 0; k < len; k++) {
  29. index = (k*col) + (i);
  30. if(index<strcall.length())
  31. cout << strcall[index];
  32. }
  33. cout << " ";
  34. }
  35. }
Add Comment
Please, Sign In to add comment