[ create a new paste ] login | about

Link: http://codepad.org/e1uwRnWn    [ raw code | output | fork ]

C++, pasted on May 17:
#include <stdio.h>
#include <stdlib.h>

#define N 20

int main(int argc, char* argv[])
{
	int A[N] = { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1 };

	for (int z = 0; z < N; z++)
		printf("%d ",A[z]);

	printf("\n");

	int max_i = 0, max_count = 0;
	for (int i = 0; i < N; i++)
	{
		int k = i;
		while (A[i] == A[i+1] && 
			A[i] == 1 && i < N-1) i++;

		if (abs(k - i) >= max_count)
		 { max_i = k; max_count = abs(k - i); }
	}

	if (max_count > 0) 
		printf("k = %d count = %d\n",max_i, max_count+1);
	else printf("00\n");

	return 0;
}


Output:
1
2
0 1 1 0 0 1 0 0 0 0 1 1 1 1 1 0 0 1 1 1 
k = 10 count = 5


Create a new paste based on this one


Comments: