John_IV

E11ReverseMatrixDiagonals

Jan 23rd, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1.  
  2.    public static void main(String[] args) throws IOException {
  3.         BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
  4.  
  5.         int[] info = Arrays.stream(rd.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  6.         int row = info[0];
  7.         int cols = info[1];
  8.         int[][] mat = new int[row][cols];
  9.  
  10.         for (int i = 0; i < row; i++)
  11.             mat[i] = Arrays.stream(rd.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  12.  
  13.         int col = cols - 1;
  14.         row--;
  15.  
  16.         while (row >= 0) {
  17.             int r = row;
  18.             int c = col;
  19.  
  20.             while (c < cols && r >= 0)
  21.                 System.out.print(mat[r--][c++] + " ");
  22.  
  23.             System.out.println();
  24.  
  25.             if (--col == -1) {
  26.                 col = 0;
  27.                 row--;
  28.             }
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment