Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Boolean Matrix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// { Driver Code Starts

#include <bits/stdc++.h>
using namespace std;

// } Driver Code Ends



class Solution
{
public:
void booleanMatrix(vector<vector<int> > &A)
{
// code here
int row[A.size()]={0},col[A[0].size()]={0};
for(int i=0;i<A.size();i++){
for(int j=0;j<A[0].size();j++){
if(A[i][j]==1){
row[i]=1;col[j]=1;
}
}
}
for(int i=0;i<A.size();i++){
for(int j=0;j<A[0].size();j++){
if(row[i]==1 || col[j]==1){
A[i][j]=1;
}
}
}

}
};

// { Driver Code Starts.
int main() {
int t;
cin>>t;
while(t--)
{
int row, col;
cin>> row>> col;
vector<vector<int> > matrix(row);
for(int i=0; i<row; i++)
{
matrix[i].assign(col, 0);
for( int j=0; j<col; j++)
{
cin>>matrix[i][j];
}
}

Solution ob;
ob.booleanMatrix(matrix);


for (int i = 0; i < row; ++i)
{
for (int j = 0; j < col; ++j)
{
cout<<matrix[i][j]<<" ";
}
cout<<endl;
}
}
return 0;
}


// } Driver Code Ends