-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdd1.cpp
41 lines (40 loc) · 1.22 KB
/
pdd1.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
#include<iostream>
#include<vector>
using namespace std;
void findRowOfMost1 (vector< vector<int> > v) {
int p = v[0].size();
vector<int> maxRow;
for (; p > 0 && v[0][p - 1] != 0; p--) {}
if (p != v[0].size())
maxRow.push_back (0);
for (int i = 1; i < v.size() ; i++) {
if (v[i][p] == 0) //这行1比较少
continue;
if (p == 0) { //这行向左到头
maxRow.push_back (i);
continue;
}
if (v[i][p - 1] == 0) { //这行1一样多
maxRow.push_back (i);
continue;
}
maxRow.swap (vector<int>()); //这行1比上一行多
maxRow.push_back (i);
for (; p > 0 && v[i][p - 1] != 0; p--) {}
}
for (int i = 0; i < maxRow.size() ; i++) {
cout << '[' << maxRow[i] + 1 << ','
<< v[0].size() - p << ']' << endl;
}
}
int main() {
vector< vector<int> > v1 = { { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 },
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}
};
findRowOfMost1 (v1);
return 0;
}