Advertisement
tepyotin2

Puddles

Dec 9th, 2023
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     ios_base::sync_with_stdio(0), cin.tie(0);
  7.     // freopen("puddles.in", "r", stdin);
  8.     int n, m;
  9.     cin >> n >> m;
  10.     string val;
  11.     char pos[n][m];
  12.     for(int i=0; i<n; i++){
  13.         cin >> val;
  14.         for(int j=0; j<m; j++){
  15.             pos[i][j] = val[j];
  16.         }
  17.     }
  18.     int ans = 0;
  19.     for(int i=0; i<n; i++){
  20.         for(int j=0; j<m; j++){
  21.             if(pos[i][j] == '#'){
  22.                 ans++;
  23.                 if(j+1<m && pos[i][j+1] == '#'){
  24.                     pos[i][j+1] = '.';
  25.                 }
  26.                 if(i+1<n && pos[i+1][j] == '#'){
  27.                     pos[i+1][j] = '.';
  28.                 }
  29.             }
  30.         }
  31.     }
  32.     cout << ans << '\n';
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement