-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem1_1.java
82 lines (61 loc) · 1.78 KB
/
Problem1_1.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
package Problem1;
import java.util.Scanner;
public class Problem1_1 {
public static void markRow(int rowArr[], int row , int col){
rowArr[row] = 1;
}
public static void markCol(int colArr[] , int row , int col){
colArr[col] = 1;
}
public static void markRow(int arr[][] , int row){
for(int i = 0; i < arr.length; i++){
arr[i][row] = 0;
}
}
public static void markCol(int arr[][] , int col){
for(int i = 0; i < arr[0].length; i++){
arr[col][i] = 0;
}
}
public static int[][] fun(int arr[][] , int row[],int col[] , int n , int m){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(arr[i][j] == 0){
markRow(row, i , j);
markCol(col, i , j);
}
}
}
for(int i = 0; i < n; i++){
if(row[i] == 1){
markRow(arr , i );
}
}
for(int i = 0; i < m; i++){
if(col[i] == 1){
markCol(arr , i );
}
}
return arr;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int arr[][] = new int[n][m];
int row[] = new int[n];
int col[] = new int[m];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
arr[i][j] = sc.nextInt();
}
}
int res[][] = fun(arr,row,col, n, m);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}