Advertisement
Adrita

sem 2 lab 3 uva 572 floodfill oil deposit

Jul 8th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int m,n;
  4. char c[101][101];
  5.  
  6. void oil(int x,int y)
  7. {
  8. if(x < 0 || y < 0 || x == m || y == n)
  9. return;
  10. if(c[x][y] != '@')
  11. return;
  12. if(c[x][y] == '@')
  13. c[x][y] = '*';
  14. oil(x,y+1);
  15. oil(x,y-1);
  16. oil(x+1,y);
  17. oil(x-1,y);
  18. oil(x+1,y+1);
  19. oil(x+1,y-1);
  20. oil(x-1,y+1);
  21. oil(x-1,y-1);
  22. }
  23. int main()
  24. {
  25. int count;
  26. x:
  27. scanf("%d %d",&m,&n);
  28. {
  29. if(m == 0)
  30. return 0;
  31. for(int i = 0; i < m; i++)
  32. {
  33. scanf("%s",&c[i]);
  34. }
  35. count = 0;
  36. for(int i = 0; i < m; i++)
  37. {
  38. for(int j = 0; j < n; j++)
  39. {
  40. if(c[i][j] != '*')
  41. {
  42. oil(i,j);
  43. count++;
  44. }
  45. }
  46. }
  47. printf("%d \n",count);
  48. }
  49. goto x;
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement