Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int m, n, povrsinaOblasti;
- int a[100][100];
- void izolovanaOblast(int y, int x)
- {
- a[y][x] = 1;
- povrsinaOblasti++;
- if((y>0) && (a[y-1][x] == 0))
- izolovanaOblast(y-1, x);
- if((x>0) && (a[y][x-1] == 0))
- izolovanaOblast(y, x-1);
- if((x<n-1) && (a[y][x+1] == 0))
- izolovanaOblast(y, x+1);
- if((y<m-1) && (a[y+1][x] == 0))
- izolovanaOblast(y+1, x);
- }
- int main()
- {
- cin >> m >> n;
- for (int i=0; i<m; i++)
- for (int j=0; j<n; j++)
- cin >> a[i][j];
- int brIzolovanihOblasti = 0;
- for (int i=0; i<m; i++)
- for (int j=0; j<n; j++)
- if(a[i][j] == 0)
- {
- brIzolovanihOblasti++;
- povrsinaOblasti = 0;
- izolovanaOblast(i,j);
- cout << i << ", " << j << " povrsina: " << povrsinaOblasti << endl;
- }
- cout << brIzolovanihOblasti << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement