Guest User

Untitled

a guest
Apr 25th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4. public static void main(String args[]) {
  5. Scanner sc = new Scanner(System.in);
  6. int T = Integer.parseInt(sc.nextLine());
  7. while (T-- > 0) {
  8. String s = sc.nextLine();
  9. double root = Math.sqrt((double)s.length());
  10.  
  11. if (root %1 != 0.0)
  12. System.out.println("INVALID");
  13.  
  14. else {
  15. char matrix[][] = new char[(int)root][(int)root];
  16. for (int i = 0, z = 0; i < root; i++)
  17. for (int j = 0; j < root; j++, z++) {
  18. matrix[i][j] = s.charAt(z);
  19. }
  20.  
  21. for (int i = 0; i < root; i++)
  22. for (int j = 0; j < root; j++) {
  23. System.out.print(matrix[j][i]);
  24. }
  25. System.out.println();
  26. }
  27. }
  28. }
  29. }
Add Comment
Please, Sign In to add comment