fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. int main() {
  6.  
  7. constexpr size_t message_char_limit = 1000;
  8.  
  9. std::ios_base::sync_with_stdio(false);
  10. std::cin.tie(nullptr);
  11.  
  12. unsigned short N;
  13. std::cin >> N;
  14. std::cin.ignore();
  15.  
  16. for (unsigned short i{ 0 }; i < N; ++i)
  17. {
  18. std::string message;
  19. message.reserve(message_char_limit);
  20. std::getline(std::cin, message);
  21. //std::cin.ignore();
  22.  
  23. unsigned short L = message.size();
  24. unsigned short M = L;
  25. // double sqertewt = std::floor(sqrt(M));
  26. while (std::floor(sqrt(M)) * std::floor(sqrt(M)) != M)
  27. {
  28. ++M;
  29. }
  30.  
  31. //message.append(M - L, '*');
  32. size_t sqrtM = sqrt(M);
  33.  
  34. for (short j{ 0}; j < sqrtM; ++j)
  35. {
  36. for (size_t k{ 1 }; k <= sqrtM; ++k)
  37. {
  38. int idx = M - k*sqrtM + j;
  39. if (M - k*sqrtM + j < L)
  40. std::cout << message[M - k*sqrtM + j];
  41. }
  42. }
  43. std::cout << "\n";
  44. }
  45.  
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 15240KB
stdin
2
iloveyoutooJill
TheContestisOver
stdout
iteiloylloooJuv
OsoTvtnheiterseC