-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBooleanMatrix.cpp
More file actions
64 lines (61 loc) · 967 Bytes
/
BooleanMatrix.cpp
File metadata and controls
64 lines (61 loc) · 967 Bytes
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
// Given a boolean matrix mat[M][N] of size M X N, modify it such that if a matrix cell mat[i][j] is 1 (or true) then make all the cells of ith row and jth column as 1.
// Example:
// Input:
// 3
// 2 2
// 1 0
// 0 0
// 2 3
// 0 0 0
// 0 0 1
// 4 3
// 1 0 0
// 1 0 0
// 1 0 0
// 0 0 0
// Output:
// 1 1
// 1 0
// 0 0 1
// 1 1 1
// 1 1 1
// 1 1 1
// 1 0 0
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int m,n;
cin>>m>>n;
int i,j,x;
int r[m]={0};
int c[n]={0};
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>x;
if(x==1)
{
r[i]=1;
c[j]=1;
}
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(r[i]||c[j])
cout<<1<<" ";
else
cout<<0<<" ";
}
cout<<"\n";
}
}
return 0;
}