forked from Hawstein/cracking-the-coding-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.7.cpp
48 lines (46 loc) · 1.03 KB
/
1.7.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
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
void zero(int **a, int m, int n){
bool row[m], col[n];
memset(row, false, sizeof(row));
memset(col, false, sizeof(col));
for(int i=0; i<m; ++i)
for(int j=0; j<n; ++j)
if(a[i][j] == 0){
row[i] = true;
col[j] = true;
}
for(int i=0; i<m; ++i)
for(int j=0; j<n; ++j)
if(row[i] || col[j])
a[i][j] = 0;
}
int main()
{
freopen("1.7.in", "r", stdin);
int m, n;
cin>>m>>n;
int **a;
a = new int*[m];
for(int i=0; i<m; ++i)
a[i] = new int[n];
for(int i=0; i<m; ++i)
for(int j=0; j<n; ++j)
cin>>a[i][j];
for(int i=0; i<m; ++i){
for(int j=0; j<n; ++j)
cout<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
zero(a, m, n);
for(int i=0; i<m; ++i){
for(int j=0; j<n; ++j)
cout<<a[i][j]<<" ";
cout<<endl;
}
fclose(stdin);
return 0;
}