[ create a new paste ] login | about

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

C++, pasted on Sep 22:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
	char str[256] = "000011111000011100000111111100000111111110000001111111\0";

	int max = 256, max_pos = 0;
	for (int i = 0; str[i] != '\0'; i++)
	{
		int k = i;
		while (str[i] == str[i+1] && 
			str[i] != '\0') i++;

		int len = abs((k+1)-i);
		if (len < max) { max = len; max_pos = k; } 
	}

	printf("str = %s\nmax_pos = %d max_len = %d\n",str,max_pos,max);

	return 0;
}


Output:
1
2
str = 000011111000011100000111111100000111111110000001111111
max_pos = 13 max_len = 1


Create a new paste based on this one


Comments: