fork(1) download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. import java.io.PrintWriter;
  6.  
  7. public class Main {
  8.  
  9. public static void main(String[] args) throws IOException {
  10.  
  11. PrintWriter out = new PrintWriter(System.out);
  12.  
  13. String str = br.readLine();
  14. int L = str.length();
  15.  
  16. int H = (int) Math.ceil(Math.sqrt(L));
  17. int W = H;
  18.  
  19. if (H * (W - 1) >= L) {
  20. W--;
  21. }
  22.  
  23. int k = 0;
  24. char[][] arr = new char[W][H];
  25. for (int r = 0; r < W; r++) {
  26. for (int c = 0; c < H; c++) {
  27. if (k < str.length())
  28. arr[r][c] = str.charAt(k++);
  29.  
  30. }
  31. }
  32.  
  33. StringBuffer sb = new StringBuffer("");
  34. for (int c = 0; c < H; c++) {
  35. for (int r = 0; r < W; r++) {
  36. if (arr[r][c] != ' ')
  37. sb = sb.append(arr[r][c]);
  38. }
  39. sb.append(" ");
  40. }
  41.  
  42. out.println(sb);
  43.  
  44. out.close();
  45. }
  46. }
  47.  
Success #stdin #stdout 0.08s 381184KB
stdin
feedthedog
stdout
fto ehg ee dd