Advertisement
Guest User

name

a guest
Apr 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<iostream>
  2. #include<queue>
  3. using namespace std;
  4. main(){
  5. int I,J,i,j,k=0,n,m; queue<int>q;
  6. cin>>n>>m;string a[n];
  7. for(i=0;i<n;++i)cin>>a[i];
  8. for(I=0;I<n;++I)for(J=0;J<m;++J)
  9. if(a[I][J]=='#'){k++;
  10. a[I][J]='.';q.push(I);q.push(J);
  11. while(!q.empty()){
  12. i=q.front();q.pop();j=q.front();q.pop();
  13. if(i && a[i-1][j]=='#'){
  14. a[i-1][j]='.';q.push(i-1);q.push(j);}
  15. if(i<n-1 && a[i+1][j]=='#'){
  16. a[i+1][j]='.';q.push(i+1);q.push(j);}
  17. if(j && a[i][j-1]=='#'){
  18. a[i][j-1]='.';q.push(i);q.push(j-1);}
  19. if(j<m-1 and a[i][j+1]=='#'){
  20. a[i][j+1]='.';q.push(i);q.push(j+1);}}}
  21. cout<<k;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement