Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int check_neighbors(vector<vector<char> > vec, int row, int col)
- {
- int neighbors = 0;
- if(row + 1 < vec.size())
- {
- if(vec[row + 1][col] == 'X')
- neighbors++;
- if(col + 1 < vec[0].size())
- {
- if(vec[row + 1][col + 1] == 'X')
- neighbors++;
- }
- if(col - 1 >= 0)
- {
- if(vec[row + 1][col - 1] == 'X')
- neighbors++;
- }
- }
- if(row - 1 >= 0)
- {
- if(vec[row - 1][col] == 'X')
- neighbors++;
- if(col + 1 < vec[0].size())
- {
- if(vec[row - 1][col + 1] == 'X')
- neighbors++;
- }
- if(col - 1 >= 0)
- {
- if(vec[row - 1][col - 1] == 'X')
- neighbors++;
- }
- }
- if(col + 1 < vec[0].size())
- {
- if(vec[row][col + 1] == 'X')
- neighbors++;
- }
- if(col - 1 >= 0)
- {
- if(vec[row][col - 1] == 'X')
- neighbors++;
- }
- return neighbors;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement