Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int size = in.nextInt();
- int[][] arr = new int[size][size];
- for(int i = 0; i < size; i++) {
- for(int j = 0; j < size; j++) {
- arr[i][j] = in.nextInt();
- }
- }
- boolean[] arrBool = new boolean[size * size];
- for(int i = 0; i < size; i++) {
- for(int j = 0; j < size; j++) {
- if(arr[i][j] != 0) {
- arrBool[arr[i][j] - 1] = true;
- }
- }
- }
- for(int i = 0; i < size; i++) {
- for(int j = 0; j < size; j++) {
- if(arr[i][j] == 0) {
- for(int t = 0; t < (size * size); t++) {
- if(!arrBool[t]) {
- arrBool[t] = true;
- arr[i][j] = t + 1;
- break;
- }
- }
- }
- }
- }
- for(int i = 0; i < size; i++) {
- for(int j = 0; j < size; j++) {
- System.out.print(arr[i][j] + " ");
- }
- if (i != size - 1)
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement