fork(2) download
  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6.  
  7. class Solution {
  8.  
  9. public static void main(String[] args) throws IOException {
  10. String s = f.readLine();
  11.  
  12. int L = s.length();
  13. int rows = (int)Math.floor(Math.sqrt(L));
  14. int columns = (int) Math.ceil(Math.sqrt(L));
  15. if (L > rows * columns)
  16. rows = (int) Math.ceil(Math.sqrt(L));
  17. char[][] ct = new char[rows][columns];
  18. int i = 0; // index into s
  19. for (int j = 0; j < rows; j++) {
  20. for (int k = 0; k < columns; k++) {
  21. if (i < L) {
  22. ct[j][k] = s.charAt(i);
  23. i++;
  24. }
  25. }
  26. }
  27.  
  28. for (int m = 0; m < columns; m++) {
  29. for (int n = 0; n < rows; n++) {
  30. System.out.print(ct[n][m]);
  31. }
  32. System.out.print(" ");
  33. }
  34. }
  35. }
Success #stdin #stdout 0.11s 320256KB
stdin
feedthedog
stdout
fto ehg ee dd