fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t;
  8. cin>>t;
  9.  
  10. while(t--)
  11. {
  12. int n;
  13. cin>>n;
  14.  
  15. string str;
  16. cin>>str;
  17. string str2=str;
  18. if(n==1)
  19. {
  20. if(str[0]=='0')
  21. cout<<"1\n";
  22. else
  23. cout<<"0\n";
  24. return 0;
  25. }
  26. int cnt=0;
  27. for(int i=0;i<n;i++)
  28. {
  29. if(i==0&&(str[0]=='1'||str[1]=='1'))
  30. cnt++;
  31. else if(i==n-1&&(str[i]=='1'||str[i-1]=='1'))
  32. cnt++;
  33. else if(str[i]=='1'||str[i+1]=='1'||str[i-1]=='1')
  34. cnt++;
  35. }
  36. cout<<n-cnt<<"\n";
  37. }
  38.  
  39. }
  40.  
Runtime error #stdin #stdout 0s 4392KB
stdin
Standard input is empty
stdout
Standard output is empty