-
Notifications
You must be signed in to change notification settings - Fork 24
/
ColoredStrokes.cpp
50 lines (43 loc) · 1.42 KB
/
ColoredStrokes.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
#include <string>
#include <vector>
using namespace std;
class ColoredStrokes {
public:
int getLeast(vector <string> p) {
int result = 0;
for (int i = 0; i < p.size(); ++i) {
for (int j = 0; j < p[i].size(); ++j) {
if (p[i][j] == 'R') {
++result;
int jj = j;
while (jj < p[0].size() && (p[i][jj] == 'R' || p[i][jj] == 'G')) {
if (p[i][jj] == 'R') {
p[i][jj] = 'X';
}
++jj;
}
}
}
}
for (int i = 0; i < p.size(); ++i) {
for (int j = 0; j < p[i].size(); ++j) {
if (p[i][j] == 'B') {
++result;
int ii = i;
while (ii < p.size() && (p[ii][j] == 'B' || p[ii][j] == 'G')) {
p[ii][j] = 'X';
++ii;
}
}
}
}
for (int i = 0; i < p.size(); ++i) {
for (int j = 0; j < p[i].size(); ++j) {
if (p[i][j] == 'G') {
++result;
}
}
}
return result;
}
};