fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int x, y;
  6. cin >> x >> y;
  7. bool **mas = new bool*[x];
  8. for (int i = 0; i < x; ++i){
  9. mas[i] = new bool[y];
  10. }
  11. for (int i = 0; i < x; ++i){
  12. for (int j = 0; j < y; ++j){
  13. char buff;
  14. cin >> buff;
  15. if (buff == '.') mas[i][j] = true;
  16. else mas[i][j] = false;
  17. }
  18. cout << endl;
  19. }
  20. int sum = 0;
  21. for (int i = 0; i < x; ++i){
  22. for (int j = 0; j < y; ++j){
  23. if (mas[i][j]){
  24. if (i - 1 >= 0 && j - 1 >= 0) if (mas[i - 1][j] && mas[i][j - 1]) ++sum;
  25. if (i - 1 >= 0 && j + 1 < y) if (mas[i - 1][j] && mas[i][j + 1]) ++sum;
  26. if (i + 1 < x && j + 1 < y) if (mas[i + 1][j] && mas[i][j + 1]) ++sum;
  27. if (i + 1 < x && j - 1 >= 0) if (mas[i + 1][j] && mas[i][j - 1]) ++sum;
  28. }
  29. }
  30. }
  31. cout << sum;
  32. return 0;
  33. }
Success #stdin #stdout 0s 4280KB
stdin
2 2
..
..
stdout

4