-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10946.cpp
More file actions
56 lines (53 loc) · 1.3 KB
/
10946.cpp
File metadata and controls
56 lines (53 loc) · 1.3 KB
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
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
char a[1000][1000];
int N, M;
struct data {
int x;
char c;
};
int call(int i, int j, char ch) {
if (i < 0 || j < 0 || i >= N || j >= M) return 0;
if (a[i][j] != ch) return 0;
a[i][j] = '.';
int sum = 1;
for (int k = 0; k < 8; k++) {
sum += call(i + dx[k], j + dy[k], ch);
}
return sum;
}
bool comp(data m, data n) {
if (n.x == m.x)
return m.c < n.c;
else
return m.x > n.x;
}
int main() {
data dd;
vector<data> v;
int n, m, tc, t = 1;
while (scanf("%d%d", &n, &m)) {
if (n == 0 && m == 0) return 0;
getchar();
N = n;
M = m;
v.clear();
for (int i = 0; i < n; i++) gets(a[i]);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] >= 'A' && a[i][j] <= 'Z') {
int k = a[i][j] - 'A';
dd.c = a[i][j];
dd.x = call(i, j, a[i][j]);
v.push_back(dd);
}
}
}
sort(v.begin(), v.end(), comp);
printf("Problem %d:\n", t++);
for (int i = 0; i < v.size(); i++) printf("%c %d\n", v[i].c, v[i].x);
}
return 0;
}