/* Tue Mar 16 19:55:55 JST 2004 */ #include #include int h, w; char picture[1024][128]; int list[8192]; int n_list; int intcmp(const void *_x, const void *_y) { int *x = (int *)_x, *y = (int *)_y; if (*x < *y) return -1; if (*x > *y) return +1; return 0; } int trapezoid(int sx, int sy) { int x, y, ulen, llen, dx, tx, height; /* Upper Horizontal Edge */ for (x = sx, y = sy; ; x++) { if (picture[y][x] != '*') { ulen = x - sx; break; } picture[y][x] = ' '; } x--; /* Search Next Edge */ for (dx = 1; dx >= -1; dx--) { if (picture[y+1][x+dx] == '*') { break; } } /* Right Edge */ for (x += dx, y++; ; x += dx, y++) { if (picture[y][x] != '*') { break; } picture[y][x] = ' '; } x -= dx, y--; tx = x; height = y - sy + 1; /* Lower Horizontal Edge */ for (x--; ; x--) { if (picture[y][x] != '*') { llen = tx - x; break; } picture[y][x] = ' '; } x++; /* Search Next Edge */ for (dx = 1; dx >= -1; dx--) { if (picture[y-1][x+dx] == '*') { break; } } /* Left Edge */ for (x += dx, y--; ; x += dx, y--) { if (picture[y][x] != '*') { break; } picture[y][x] = ' '; } return (ulen + llen) * height / 2; } int main() { int each, i, j, x, y, n; char s[1024]; for (each = 0; ; each++) { gets(s); h = atoi(s); if (h == 0) { break; } w = 0; for (i = 0; i < h; i++) { gets(picture[i]); if (w < strlen(picture[i])) { w = strlen(picture[i]); } } for (i = 0; i < h; i++) { for (j = strlen(picture[i]); j < w; j++) { picture[i][j] = ' '; } picture[i][w] = '\0'; } n_list = 0; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { if (picture[y][x] == '*') { list[n_list++] = trapezoid(x, y); } } } list[n_list] = INT_MAX; qsort(list, n_list, sizeof(int), intcmp); n = 1; if (each > 0) { printf("----------\n"); } for (i = 0; i < n_list; i++) { if (list[i] != list[i+1]) { printf("%d %d\n", list[i], n); n = 1; } else { n++; } } } return 0; } /* Tue Mar 16 20:39:54 JST 2004 */