Advertisement
Ansaid

Yandex1

Feb 7th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1.  
  2. package com.company;
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         Scanner in = new Scanner(System.in);
  11.         int size = in.nextInt();
  12.         int[][] arr = new int[size][size];
  13.  
  14.         for(int i = 0; i < size; i++) {
  15.             for(int j = 0; j < size; j++) {
  16.                 arr[i][j] = in.nextInt();
  17.             }
  18.         }
  19.  
  20.         boolean[] arrBool = new boolean[size * size];
  21.  
  22.         for(int i = 0; i < size; i++) {
  23.             for(int j = 0; j < size; j++) {
  24.                 if(arr[i][j] != 0) {
  25.                     arrBool[arr[i][j] - 1] = true;
  26.                 }
  27.             }
  28.         }
  29.  
  30.         for(int i = 0; i < size; i++) {
  31.             for(int j = 0; j < size; j++) {
  32.                 if(arr[i][j] == 0) {
  33.                     for(int t = 0; t < (size * size); t++) {
  34.                         if(!arrBool[t]) {
  35.                             arrBool[t] = true;
  36.                             arr[i][j] = t + 1;
  37.                             break;
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.  
  44.         for(int i = 0; i < size; i++) {
  45.             for(int j = 0; j < size; j++) {
  46.                 System.out.print(arr[i][j] + " ");
  47.             }
  48.             if (i != size - 1)
  49.                 System.out.println();
  50.         }
  51.  
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement