Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. int check_neighbors(vector<vector<char> > vec, int row, int col)
  2. {
  3. int neighbors = 0;
  4.  
  5. if(row + 1 < vec.size())
  6. {
  7. if(vec[row + 1][col] == 'X')
  8. neighbors++;
  9.  
  10. if(col + 1 < vec[0].size())
  11. {
  12. if(vec[row + 1][col + 1] == 'X')
  13. neighbors++;
  14. }
  15.  
  16. if(col - 1 >= 0)
  17. {
  18. if(vec[row + 1][col - 1] == 'X')
  19. neighbors++;
  20. }
  21. }
  22.  
  23. if(row - 1 >= 0)
  24. {
  25. if(vec[row - 1][col] == 'X')
  26. neighbors++;
  27.  
  28. if(col + 1 < vec[0].size())
  29. {
  30. if(vec[row - 1][col + 1] == 'X')
  31. neighbors++;
  32. }
  33.  
  34. if(col - 1 >= 0)
  35. {
  36. if(vec[row - 1][col - 1] == 'X')
  37. neighbors++;
  38. }
  39. }
  40.  
  41. if(col + 1 < vec[0].size())
  42. {
  43. if(vec[row][col + 1] == 'X')
  44. neighbors++;
  45. }
  46.  
  47. if(col - 1 >= 0)
  48. {
  49. if(vec[row][col - 1] == 'X')
  50. neighbors++;
  51. }
  52.  
  53. return neighbors;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement