#include #include #include using namespace std; const int NLOW = 4; const int NHIGH = 9; const int MLOW = 2; const int MHIGH = 10; const int EMPTY = 0; const int SECTION = 1; int grid[NHIGH+2][NHIGH+2]; int fill(int i, int j) { if (grid[i][j] == EMPTY) return 0; grid[i][j] = EMPTY; return 1 + fill(i+1,j) + fill(i-1,j) + fill(i,j+1) + fill(i,j-1); } int main() { int n, m, t, r, c; char op; cin >> n >> m >> t >> op; if (n < NLOW || n > NHIGH) { cout << "ERROR: invalid n " << n << endl; return 1; } if (m < MLOW || m > MHIGH) { cout << "ERROR: invalid m " << m << endl; return 2; } if (t < 0) { cout << "ERROR: invalid t" << t << endl; return 3; } if (op != '+' && op != '-' && op != '*' && op != '/') { cout << "ERROR: invalid op" << op << endl; return 4; } for(int i=0; i> r >> c; if (r < 1 || r > n) { cout << "ERROR: invalid r " << r << endl; return 5; bad = true; } if (c < 1 || c > n) { cout << "ERROR: invalid c " << c << endl; return 6; bad = true; } if (!bad) { if (grid[r][c] == SECTION) { cout << "ERROR: repeat square " << r << ',' << c << endl; return 7; } grid[r][c] = SECTION; } } if (!bad) { int nfill = fill(r, c); if (nfill != m) { cout << "ERROR: squares do not make a connected section" << endl; return 8; } } return 42; }