forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountingstars.cpp
63 lines (52 loc) · 1.25 KB
/
countingstars.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
59
60
61
62
63
#include <iostream>
#include <vector>
using namespace std;
struct pixel {
char c;
bool used;
};
int floodfill(int m, int n, int i, int j, vector<vector<pixel>>& v) {
// If out of bounds
if(i < 0 || i >= m || j < 0 || j >= n) {
return 0;
}
// If already used
if(v[i][j].used) {
return 0;
}
// Use this point
v[i][j].used = true;
// Use all adjacent points
floodfill(m, n, i, j+1, v);
floodfill(m, n, i, j-1, v);
floodfill(m, n, i+1, j, v);
floodfill(m, n, i-1, j, v);
return 1;
}
int main() {
int m, n;
int count = 1;
while(cin >> m && cin >> n) {
vector<vector<pixel>> v;
for(int i = 0; i < m; i++) {
vector<pixel> temp;
for(int i = 0; i < n; i++) {
char c;
cin >> c;
pixel p;
p.c = c;
p.used = (c == '#');
temp.push_back(p);
}
v.push_back(temp);
}
int stars = 0;
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
stars += floodfill(m, n, i, j, v);
}
}
cout << "Case " << count << ": " << stars << endl;
count++;
}
}