Advertisement
LEGEND2004

Junior C

Feb 9th, 2024
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int cnt[105];
  5.  
  6. signed main()
  7. {
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0);
  10.  
  11.  
  12.     int t , n;
  13.     string s;
  14.     cin >> t;
  15.     int ans = 0;
  16.     while(t--){
  17.         cin >> n;
  18.         cin >> s;
  19.         int x = 0 , y = 0;
  20.         for(int i = 0; i < s.size(); i++){
  21.             if(s[i] == '1')
  22.                 x++;
  23.             else
  24.                 y++;
  25.         }
  26.         cout << min(x , y + 1) << '\n';
  27.     }
  28. }
  29.  
  30.  
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement