Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.IOException;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int rows = scanner.nextInt();
- int cols = scanner.nextInt();
- scanner.nextLine();
- int[][] matrix = new int[rows][cols];
- for (int r = 0; r < rows; r++) {
- matrix[r] = Arrays.stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt)
- .toArray();
- }
- int row = rows - 1;
- int col = cols - 1;
- while (row >= 0) {
- int r = row;
- int c = col;
- while (c < cols && r >= 0) {
- System.out.print(matrix[r--][c++] + " ");// тук направо си принтираме резултата
- }
- System.out.println();
- col--;
- if (col == -1) {// ако сме на последната колона трябва да се качим един ред нагоре, но си оставаме на първа колона
- col = 0;
- row--;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement