CF 586A 找1的个数和101的个数
Sample test(s)
input
5
0 1 0 1 1
output
4
input
7
1 0 1 0 0 1 0
output
4
input
1
0
output
0
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <string> 6 # include <cmath> 7 # include <queue> 8 # define LL long long 9 using namespace std ; 10 11 int a[200] ; 12 13 int main() 14 { 15 int n; 16 while(scanf("%d",&n) != EOF) 17 { 18 int i ; 19 int sum = 0 ; 20 int x ; 21 for (i = 0 ; i < n ; i++) 22 { 23 scanf("%d" , &x) ; 24 if (x == 1) 25 sum++ ; 26 a[i] = x ; 27 } 28 for (i = 0 ; i < n ; i++) 29 { 30 if (a[i] == 0) 31 continue ; 32 if (a[i] == 1 && a[i+1] == 0 && a[i+2] ==1) 33 sum++ ; 34 } 35 printf("%d\n" , sum) ; 36 37 } 38 return 0; 39 }