# how to count contiguous and common zeros in various arrays

• May 12th, 2014, 02:31 AM
shel88
how to count contiguous and common zeros in various arrays
Hi Friends!

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

How to write a program to count the common zero sequences and there indexes of arrays?

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
• May 12th, 2014, 02:46 AM
zizz
Re: how to count contiguous and common zeros in various arrays
Quote:

Originally Posted by shel88
How to write a program to count the common zero sequences and there indexes of arrays?

You can start by writing a program that can do that for one array. When that works you expand the program to handle several arrays.

If you can check whether a position is zero in one array it's not hard to check whether that position is zero in all of several arrays.
• May 12th, 2014, 03:26 AM
Alex F
Re: how to count contiguous and common zeros in various arrays
Create summary array which contains sum of total values of input arrays in every position. Count contiguous zeros in it. Algorithm for one array is trivial.
The point here is that summary array has 0 in position i, only of all input arrays have 0 in this position.