fork(2) download
  1. #include<iostream>
  2.  
  3. using namespace std;
  4. int main()
  5. {
  6. int t,i,total,n;
  7. char a[1001];
  8. cin>>t;
  9. while(t--)
  10. {
  11. i=0;
  12. cin>>n;
  13. total=n;
  14. cin>>a;
  15. while(i<n)
  16. {
  17. if(a[i]=='1')
  18. {
  19. if(i==0)
  20. total-=2;
  21.  
  22. else if(i==1)
  23. {
  24. if(a[i-1]=='1')
  25. total--;
  26. else
  27. total-=3;
  28. }
  29. else if(i>1 && i<n-1)
  30. {
  31. if(a[i-1]=='1')
  32. total--;
  33. else if(a[i-2]=='1')
  34. total-=2;
  35. else
  36. total-=3;
  37. }
  38. else
  39. {
  40. if(a[i-1]=='1');
  41. else if(a[i-2]=='1')
  42. total--;
  43. else
  44. total-=2;
  45. }
  46. }
  47. i++;
  48. }
  49. if(total<0)
  50. total=0;
  51. cout<<total<<"\n";
  52.  
  53.  
  54. }
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 3300KB
stdin
1 49 0101100010101110000101111101101010011010001100111
stdout
4