fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String line = br.readLine();
  13. String[] values = line.split(" ");
  14. int m = Integer.parseInt(values[0]); // rows
  15. int n = Integer.parseInt(values[1]); // coloumns
  16.  
  17. int[][] newmatrix = new int[m][n+m-1];
  18.  
  19. int skip =0;
  20. for(int row = 0 ; row < m; row++)
  21. {
  22. String line1= br.readLine();
  23. String[] values1 = line1.split(" ");
  24. for(int col=0; col< n; col++)
  25. {
  26.  
  27. newmatrix[row][col+skip]=Integer.parseInt(values1[col]);
  28. }
  29. skip++;
  30. }
  31.  
  32. for(int col1=0; col1< n+m-1; col1++)
  33. {
  34. for( int row1=0; row1 < m; row1++)
  35. {
  36. if(newmatrix[row1][col1]== 0)
  37. {}
  38. else
  39. System.out.print(newmatrix[row1][col1]+" ");
  40.  
  41. }
  42. System.out.println("\n");
  43. }
  44.  
  45.  
  46.  
  47. }
  48. }
Success #stdin #stdout 0.1s 320320KB
stdin
3 3
1 2 3
4 5 6 
7 8 9
stdout
1 

2 4 

3 5 7 

6 8 

9