fork download
  1. #include<bits/stdc++.h>
  2. #define PI acos(-1)
  3. #define min3(a,b,c) min(a,min(b,c))
  4. #define max3(a,b,c) max(a,max(b,c))
  5. #define READ(f) freopen(f, "r", stdin)
  6. #define WRITE(f) freopen(f, "w", stdout)
  7. #define lli long long int
  8. #define ull unsigned long long int
  9. #define pii pair < int, int>
  10. #define pll pair < ll, ll>
  11. #define sc scanf
  12. #define scin(x) sc("%d",&(x))
  13. #define scln(x) sc("%lld",&(x))
  14. #define pf printf
  15. #define ms(a,b) memset(a,b,sizeof(a))
  16. #define veci vector<int>
  17. #define vecl vector<long long int>
  18. #define vecp vector< pair<int,int> >
  19. #define pb push_back
  20.  
  21. long power(long int x, long int y){ int temp; if( y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return temp*temp; else return x*temp*temp; }
  22. /*lli gcd(lli x,lli y)
  23. {
  24.   if(x==0) return y;
  25.   return gcd(y%x,x);
  26. }*/
  27. using namespace std;
  28.  
  29. int main()
  30. {
  31.  
  32. int n,arr[5050],i,fence;
  33. while(scin(n) and n)
  34. {
  35. for(i=0;i<n;i++)
  36. scin(arr[i]);
  37.  
  38. fence=0;
  39. if(arr[0]==0 and arr[n-1]==0)
  40. {
  41. fence++;
  42. arr[0]=1;
  43. }
  44. for(i=1;i<=n-1;i++)
  45. {
  46. if(arr[i]==0 and arr[i-1]==0)
  47. {
  48. fence++;
  49. arr[i]=1;
  50. }
  51. }
  52.  
  53.  
  54.  
  55. cout << fence << endl;
  56. }
  57.  
  58.  
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0s 4532KB
stdin
10
1 0 0 1 0 0 1 0 1 1
11
1 0 0 1 0 0 0 1 1 0 1
12
0 0 0 0 0 1 1 0 0 0 1 1
10
0 1 0 1 0 1 1 0 1 0
0
stdout
2
2
3
1