Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- #define M 9
- #define N 9
- void color(int field[][N], int x, int y, int pc, int nc)
- {
- if (x < 0 || x >= M || y < 0 || y >= N)
- return;
- if (field[x][y] != pc)
- return;
- field[x][y] = nc;
- color(field, x+1, y, pc, nc);
- color(field, x-1, y, pc, nc);
- color(field, x, y+1, pc, nc);
- color(field, x, y-1, pc, nc);
- }
- void ff(int field[][N], int x, int y, int nc)
- {
- int pc = field[x][y];
- color(field, x, y, pc, nc);
- }
- int main()
- {
- int field[M][N] = {
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0},
- };
- int x = 5, y = 5, nc = 1;
- ff(field, x, y, nc);
- for (int i=0; i<M; i++){
- for (int j=0; j<N; j++){
- cout << field[i][j] << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement