how to count contiguous and common zeros in various arrays

If I have number of arrays (its 3 for instance) with fixed size (15), it consist of zeros and non-zeros

eg:array1[15]={5,5,0,0,4,4,4,0,0,0,1,0,0,0,3}

array2[15]={1,0,0,0,0,7,7,0,0,3,0,0,0,0,2}

array3[15]={6,6,6,0,8,8,8,0,0,0,3,3,0,0,4}

...........


sample output for the above arrays:

Index Nim_of_zeros

3 1

7 2

12 2

How can I count the common zero sequences and there indexes of arrays?
Like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int array[3][15]={
    {5,5,0,0,4,4,4,0,0,0,1,0,0,0,3},
    {1,0,0,0,0,7,7,0,0,3,0,0,0,0,2},
    {6,6,6,0,8,8,8,0,0,0,3,3,0,0,4}
};
int seq(0);
for(int i(0);i<15;i++){
    bool zero(true);
    for(int j(0);j<3;j++)if(array[j][i]!=0)zero=false;
    if(zero){
        seq++;
        continue;
    };
    if(seq){
        std::cout<<i-seq<<' '<<seq<<std::endl;
        seq=0;
    };
};
Last edited on
Just '&' the respective elements at same index from all the arrays and form a new array.

Then count the zeroes as you want.
Topic archived. No new replies allowed.