-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooleanMatrix.java
More file actions
52 lines (47 loc) · 1.6 KB
/
BooleanMatrix.java
File metadata and controls
52 lines (47 loc) · 1.6 KB
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
/**
* Created by MalhotR1 on 04/27/2017.
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class BooleanMatrix {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
for (int t = 0; t < T; t++) {
String[] in = br.readLine().trim().split(" ");
int M = Integer.parseInt(in[0]);
int N = Integer.parseInt(in[1]);
int[][] arr = new int[M][N];
int[] row = new int[M];
int[] col = new int[N];
in = br.readLine().trim().split(" ");
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
arr[i][j] = Integer.parseInt(in[j + i*N]);
if (arr[i][j] == 1) {
row[i] = 1;
col[j] = 1;
}
}
}
for (int i = 0; i < M; i++) {
if (row[i] == 1)
for (int j = 0; j < N; j++)
arr[i][j] = 1;
}
for (int i = 0; i < N; i++) {
if (col[i] == 1)
for (int j = 0; j < M; j++) {
arr[j][i] = 1;
}
}
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
System.out.print(arr[i][j]);
}
}
System.out.println();
}
}
}