fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8. int c=0,b,t;
  9. char a[1002];
  10. cin>>b;
  11. for(int i=0;i<b;i++){
  12. cin>>t;
  13. cin>>a;
  14.  
  15. if((a[0]=='0')&&(a[1]!='1')){
  16. c++;}
  17.  
  18. if((a[t-1]=='0')&&(a[t-2]!='1')){
  19. c++;
  20. }
  21. for(int j=1;j<t-1;j++){
  22. if(a[j]=='0'){
  23. if((a[j-1]=='0')&&(a[j+1]=='0'))
  24. c++;
  25. }
  26.  
  27. }
  28.  
  29. cout<<c;
  30. c=0;
  31. cout<<endl;
  32. }
  33.  
  34.  
  35.  
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 3344KB
stdin
1
1
0
stdout
2