Ankit_132

A

Nov 26th, 2023
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test  int _TEST; cin>>_TEST; while(_TEST--)
  7. #define pb     push_back
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n;
  14.         cin>>n;
  15.  
  16.         string s;
  17.         cin>>s;
  18.  
  19.         int ans = 0;
  20.  
  21.         int x = 0;
  22.  
  23.         vector<int> cnt;
  24.         cnt.pb(0);
  25.  
  26.         for(int i=0; i<n; )
  27.         {
  28.             if(s[i] == '#')
  29.             {
  30.                 i++;
  31.                 continue;
  32.             }
  33.  
  34.             while(i<n && s[i]=='.')
  35.             {
  36.                 i++;
  37.                 x++;
  38.             }
  39.  
  40.             cnt.pb(x);
  41.             x = 0;
  42.         }
  43.  
  44.         sort(cnt.begin(), cnt.end());
  45.  
  46.         if(cnt.back() < 3)
  47.             cout<<accumulate(cnt.begin(), cnt.end(), 0)<<"\n";
  48.         else
  49.             cout<<2<<"\n";
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment