fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10.  
  11. int x, y;
  12. x = in.nextInt();
  13. y = in.nextInt();
  14. boolean[][] mas = new boolean[x][y];
  15. for (int i = 0; i < x; ++i){
  16. for (int j = 0; j < y; ++j){
  17. char buff;
  18. in.useDelimiter("");
  19. buff = in.next().charAt(0);
  20. if (buff == '.') mas[i][j] = true;
  21. else mas[i][j] = false;
  22. }
  23.  
  24. }
  25. int sum = 0;
  26. for (int i = 0; i < x; ++i){
  27. for (int j = 0; j < y; ++j){
  28. if (mas[i][j]){
  29. if (i - 1 >= 0 && j - 1 >= 0) if (mas[i - 1][j] && mas[i][j - 1]) ++sum;
  30. if (i - 1 >= 0 && j + 1 < y) if (mas[i - 1][j] && mas[i][j + 1]) ++sum;
  31. if (i + 1 < x && j + 1 < y) if (mas[i + 1][j] && mas[i][j + 1]) ++sum;
  32. if (i + 1 < x && j - 1 >= 0) if (mas[i + 1][j] && mas[i][j - 1]) ++sum;
  33. }
  34. }
  35. }
  36. System.out.print(sum);
  37. in.close();
  38. return;
  39. }
  40. }
Success #stdin #stdout 0.06s 2184192KB
stdin
2 2
..
..
stdout
Standard output is empty