#include #include #define BACK 0 #define DADO 1 #define DOT 2 unsigned long int map [60][60]; char output [10000]; int maxx, maxy; int scan (int x, int y, unsigned long int search, unsigned long int sub) { /*printf ("(%d,%d)", x, y);*/ if ( (x < 0) || (y < 0) || (x >= maxx) || (y >= maxy) ) return 0; if (map [x] [y] == BACK) return 0; else if (map [x] [y] == DADO) map [x] [y] = BACK; else if (map [x] [y] == search) map [x] [y] = sub; else return 0; return scan (x + 1, y, search, sub) + scan (x - 1, y, search, sub) + scan (x, y + 1, search, sub) + scan (x, y - 1, search, sub) + 1; } int main () { FILE * pf; char input [60]; int x,y,c,dadi,th = 0; pf = fopen ("dice.in", "r+"); for (;;) { th ++; fscanf (pf, "%d %d\n", & maxx, & maxy); /*printf ("mx %d my %d\n", maxx, maxy);*/ if (maxx == 0 && maxy == 0) { fclose (pf); return 0; } /*printf ("p1\n");*/ for (y = 0; y < maxy; ++ y) { fscanf (pf, "%s\n", input); for (x = 0; x < maxx; ++ x) { map [x][y] = (input [x] == '.' ? BACK: (input [x] == '*' ? DADO : DOT)); } } /*printf ("p2\n");*/ c = 3; for (x = 0; x < maxx; ++ x) { for (y = 0; y < maxy; ++ y) { if (scan (x, y, DOT, c)) ++ c; } } /*printf ("p3\n");*/ dadi = (c -= 3); for (; c > 0; -- c) { output [c - 1] = 0; for (x = 0; x < maxx; ++ x) { for (y = 0; y < maxy; ++ y) { output [c - 1] += (scan (x, y, c + 2, BACK) ? 1 : 0); } } } /*printf ("p4\n");*/ for (x = 0; x < dadi - 1; ++ x) { for (y = x + 1; y < dadi; ++ y) { if (output [x] > output [y]) { char t = output [y]; output [y] = output [x]; output [x] = t; } } } printf ("Throw %d\n", th); for (x = 0; x < dadi - 1; ++ x) { printf ("%d ", output [x]); } printf ("%d\n\n", output [dadi - 1]); } }