forked from Hawstein/cracking-the-coding-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.7.cpp
More file actions
43 lines (41 loc) · 874 Bytes
/
1.7.cpp
File metadata and controls
43 lines (41 loc) · 874 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
#include <iostream>
#include <cstdio>
using namespace std;
void zero(int **a, int m, int n)
{
int *row = new int[m];
int *col = new int[n];
for(int i=0; i<m; ++i)
for(int j=0; j<n; ++j)
if(a[i][j] == 0)
{
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)
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];
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;
}