fork download
  1. import java.util.Scanner;
  2. public class Main
  3. {
  4. public static void main(String[]args)
  5. {
  6. Scanner sc=new Scanner(System.in);
  7.  
  8. int row=sc.nextInt();
  9. int col=sc.nextInt();
  10. char a[][]=new char[row][col];
  11. for(int i=0;i<row;i++)
  12. {
  13. for(int j=0;j<col;j++)
  14. {
  15. a[i][j]=sc.next().charAt(0);
  16. }
  17. }
  18.  
  19. StringBuilder sb=new StringBuilder();
  20. StringBuilder sb1=new StringBuilder();
  21. int symbol=0;
  22. for(int i=0;i<col;i++)
  23. {
  24. for(int j=0;j<row;j++)
  25. {
  26. char ch=a[j][i];
  27. if(Character.isLetterOrDigit(ch) && symbol==0)
  28. sb.append(ch);
  29. else if(!Character.isLetterOrDigit(ch))
  30. {
  31. sb1.append(ch);
  32. symbol++;
  33. }
  34. else
  35. {
  36. sb.append(" "+ch);
  37. sb1.setLength(0);
  38. symbol=0;
  39. }
  40. }
  41. }
  42. sb.append(sb1);
  43. System.out.println(sb);
  44. }
  45. }
Success #stdin #stdout 0.21s 59024KB
stdin
7 3
N U E S @
U G D ^ K
K A D   I
A R Y T N
% $ % H G
# & $ E
Y R I *
stdout
NSGKDRNU DKIY EU AAT$