import java util Scanner public class Task38 public static void printA

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.Scanner;
public class Task38 {
public static void printArray(int[][] a){
int n = a.length;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
public static void changeRows(int[][] a, int startRow, int row){
int[] c = new int[n];
if (a[row][startRow] != 0) {
c = a[row];
a[row] = a[startRow];
a[startRow] = c;
return;
}
changeRows(a, startRow, row + 1);
}
public static void makeRow(int rowNum, int[][] a){
int n = a.length;
if (rowNum == n) {
printArray(a);
return;
}
if (a[rowNum][rowNum] == 0) {
changeRows(a, rowNum, rowNum + 1);
}
int k = 1;
if (a[rowNum][rowNum] != 0) {
difference(a, rowNum, rowNum + 1);
}
makeRow(rowNum + 1, a);
}
public static void difference(int[][] a, int rowNum, int row){
int n = a.length;
if (row == n) {
return;
}
differenceColumn(a, rowNum, rowNum, row);
difference(a, rowNum, row + 1);
}
public static void differenceColumn(int[][] a, int rowNum, int column, int row){
if (column == a.length)
return;
int k = a[row][rowNum];
a[row][column] = a[row][column] * a[rowNum][rowNum] - a[rowNum][row] * k;
differenceColumn(a, rowNum, column + 1, row + 1);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[][] a = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = scanner.nextInt();
}
}
makeRow(0, a);
}
}