#include #include #include #define D #ifdef D #define _V(_v) cout << "Var: " #_v ": " << _v << " Line: " << __LINE__ << endl; #else #define _V(_v) #endif #define Matrix(_x, _y) (matrix[_y])[_x] #define Mark(_x, _y) markmatrix[_y][_x] int main (int c, char **v) { ifstream in ("dice.in"); int throwcount = 0; int dx, dy; while ((in >> dx >> dy), ((dx != 0) && (dy != 0))) { string* matrix = new string[dy]; int markmatrix[50][50]; int dotcounter[50]; for (int i = 0; i < 50; i++) { dotcounter[i] = 0; for (int j = 0; j < 50; j++) markmatrix[i][j] = 0; } for (int i = 0; i < dy; i++) { in >> matrix[i]; matrix[i] += string("."); } int lastdice = 0; dx++; for (int y = 0; y < dy; y++) { int tempx1, tempx2; bool status = false; bool linefound = false; for (int x = 0; x < dx; x++) { if (Matrix(x, y) != '.' && !status) { tempx1 = x; status = true; } if ((Matrix(x, y) == '.') && status) { tempx2 = x; status = false; linefound = false; int i; if (y != 0) for (i = tempx1; i < tempx2; i++) { if (Matrix(i, y - 1) != '.') { linefound = true; break; } } if (linefound) { for (int j = tempx1; j < tempx2; j++) Mark(j,y) = Mark(i, y-1); } else { lastdice++; for (int j = tempx1; j < tempx2; j++) Mark(j, y) = lastdice; } } } } #ifdef D for (int y = 0; y < dy; y++) { for (int x = 0; x < dx; x++) cout << Mark(x,y); cout << endl; } #endif for (int y = 0; y < dy; y++) for (int x = 0; x < dx; x++) { if (Matrix(x, y) == 'X') { dotcounter[Mark(x,y) - 1]++; int j = x; if (x!=dx - 1) while (Matrix(++j, y) == 'X') Matrix(j, y) = 'N'; j = y; if (y!=dy - 1) while (Matrix(x, ++j) == 'X') Matrix(x, j) = 'N'; } } cout << "Throw " << ++throwcount << endl; for (int i = 0; i < lastdice; i++) cout << dotcounter[i] << " "; cout << endl << endl; } return 0; }