-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.7.cpp
58 lines (52 loc) · 1.3 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
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string compressString(string str);
string shortenWithSameAlpha(char alpha, int duplicated_cnt);
void make_zeros(vector<vector<int> > &matrix)
{
if (matrix.size() == 0) {
return ;
}
vector<bool> rows (matrix.size(), false);
vector<bool> columns (matrix[0].size(), false);
for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix[i].size(); j++) {
if (matrix[i][j] == 0) {
rows[i] = true;
columns[j] = true;
}
}
}
for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix[i].size(); j++) {
if (rows[i] || columns[j]) {
matrix[i][j] = 0;
}
}
}
}
int main()
{
vector<vector<int> > matrix;
for (int i = 0; i < 5; i++) {
vector<int> row;
for(int j = 0; j < 8; j++) {
if ((i*8+j)%14 ==0){
row.push_back(0);
} else {
row.push_back(i*8+j);
}
}
matrix.push_back(row);
}
make_zeros(matrix);
for (int i = 0; i < 5; i++) {
for(int j = 0;j < 8; j++) {
cout << matrix[i][j] << " ";
}
cout << endl;
}
return 0;
}