fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(false);cin.tie(NULL);
  8.  
  9. int m,n;cin>>m>>n;
  10. bool arr1[m+1][n];
  11. bool arr2[m][n+1];
  12.  
  13. for (int i=0;i<=m;i++){
  14. for (int j=0;j<n;j++) arr1[i][j]=0;
  15. }for (int i=0;i<m;i++){
  16. for (int j=0;j<=n;j++) arr2[i][j]=0;
  17. }
  18.  
  19. char arr[m][n];
  20.  
  21. for (int i=0;i<m;i++){
  22. for (int j=0;j<n;j++){
  23. cin>>arr[i][j];
  24. if (arr[i][j]=='x'){
  25. arr1[i][j]=1;
  26. arr1[i+1][j]=1;
  27. arr2[i][j]=1;
  28. arr2[i][j+1]=1;
  29. }
  30. }
  31. }
  32.  
  33. int ans=0;
  34.  
  35. for (int i=0;i<=m;i++){
  36. for (int j=0;j<n;j++){
  37. if (arr1[i][j]){
  38. if (i==0||i==n)ans++;
  39. else if ((arr[i-1][j]=='x')^(arr[i][j]=='x'))ans++;
  40. }
  41. }
  42. }
  43.  
  44. for (int i=0;i<m;i++){
  45. for (int j=0;j<=n;j++){
  46. if (arr2[i][j]){
  47. if (j==0||j==n)ans++;
  48. else if ((arr[i][j-1]=='x')^(arr[i][j]=='x'))ans++;
  49. }
  50. }
  51. }
  52.  
  53. cout<<ans<<endl;
  54. return 0;
  55. }
Success #stdin #stdout 0.04s 7804KB
stdin
Standard input is empty
stdout
0