-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path137.cpp
60 lines (55 loc) · 1.03 KB
/
137.cpp
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
#include<bits/stdc++.h>
using namespace std;
void nhap(bool a[105][105],int m,int n){
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
}
void in(bool a[105][105],int m,int n){
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
void modifyMatrix(bool mat[105][105],int m,int n) {
bool row[m];
bool col[n];
for (int i = 0; i < m; i++) {
row[i] = 0;
}
for (int j = 0; j < n; j++) {
col[j] = 0;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (mat[i][j] == 1) {
row[i] = 1;
col[j] = 1;
}
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if ( row[i] == 1 || col[j] == 1 ) {
mat[i][j] = 1;
}
}
}
in(mat,m,n);
}
int main(){
int t;
cin>>t;
while(t--){
int m,n;
bool a[105][105];
cin>>m>>n;
nhap(a,m,n);
modifyMatrix(a,m,n);
}
return 0;
}